<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.5.0 - 10.10.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSGarbageCollector/disableCollectorForPointer:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSGarbageCollector(im)disableCollectorForPointer:"
  },
  "title" : "disableCollectorForPointer:"
}
-->

# disableCollectorForPointer:

Specifies that a given pointer will not be collected.

```
- (void) disableCollectorForPointer:(const void *) ptr;
```

## Parameters

`ptr`

A pointer to the memory that should not be collected.

## Discussion

You use this method to ensure that memory at a given address will not be collected. You can use this, for example, to create new root objects:

```objc
NSMutableDictionary *globalDictionary;
globalDictionary = [NSMutableDictionary dictionary];
[[NSGarbageCollector defaultCollector]
    disableCollectorForPointer:globalDictionary];
```

The new dictionary will not be collectable and will persist for the lifetime of the application unless it is subsequently passed as the argument to [`enableCollectorForPointer:`](/documentation/Foundation/NSGarbageCollector/enableCollectorForPointer:). For more about root objects and scanned memory, see Garbage Collection Programming Guide.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)