Objective-C [on OS X Leopard] Garbage collection, no Question

I have a question about garbage collection in Objective-C

If I have an object, let's call it "A". And "A" contains instance variables that point to several other objects. If I set the pointer equal to A equal to zero, the garbage collector will understand that everything that is contained in "A" is also not used now and handles cleaning? Or do I also need to explicitly make all instance variables in "A" nil to clear the memory?

+3
source share
2 answers

Yes, it just works; the collector knows that a subgraph of objects, potentially complexly connected, which no longer has any connections from living objects, is garbage.

The collector also detects a full cycle.

+4
source

Yes, absolutely, it will work.

HOWEVER, note that garbage collection is not deterministic, that is, it is not reported when it will work.

Therefore, any destructors that you must call will not be called immediately when you do not specify a pointer.

If object "A" is or contains links to file objects, database objects, connection objects, etc., you will need to use reference counting to ensure that they are immediately released.

Otherwise use GC; it is much less painful.

+1
source