In real, real garbage collection, this code could potentially be a problem. Objects can be freed as soon as they are no more, and the compiler can refuse the link at any time if you will never use it again. For optimization purposes, an area is just a way to impose an upper limit on such a thing, rather than dictating it absolutely.
You can use NSAllocateCollectable to bind life cycle calculations to C primitive pointers, although it's messy and slightly confusing.
Garbage collection has never been implemented on iOS and is now deprecated on Mac (as indicated at the bottom of this FAQ ), in both cases in favor of automatic link counting (ARC). ARC adds retain and releases , where it can see that they are implicitly needed. Unfortunately, it can perform some neat tricks that were not previously possible, for example, retrieving objects from the startup pool if they were used as the return results. Thus, it has the same net effect as the garbage collection approach - an object can be released at any time after the final link to it disappears.
A workaround would be to create a class like:
@interface PFDoNothing + (void)doNothingWith:(id)object; @end
What is implemented to do nothing. Submit your auto-implemented object after you finish using the internal memory. Objective-C dynamic dispatch means that the compiler is unsafe to optimize the call - it does not know that you (or the KVO mechanisms or any other actor) did not do something like the swizzle method at runtime.
EDIT: NSData is a special case because it offers direct C-level access to object-oriented memory, and it is easy to find an explicit discussion of the situation with GC. See this thread on Cocoabuilder for a pretty good one, although the same caution applies as above, that is, garbage collection is outdated, and automatic link counting works differently.
Tommy source share