As per:
<http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html >

"You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. You are responsible for relinquishing ownership of objects you own using release or autorelease. Any other time you receive an object, you must not release it."

If your object, at any point in its lifecycle, takes ownership of another object then it has to release that object or you'll have a potential resource leak. Usually the best place to do this is in the dealloc method of the object. When dealloc is called on your object it can run cleanup code and release anything it needs to release. The runtime will then call dealloc on any objects that need it, and so on. In this way your tree will traverse itself and deallocate any resources that need to be taken care of.

This is the great thing about following the memory management guidelines and good object oriented principles, your objects can mostly take care of themselves if you set them up properly.

Note that if you are using garbage collection most of this goes out the window. The runtime will handle most of it for you, however you might still need to use stuff like the finalize method to take care of issues other than object ownership:

<http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/GarbageCollection/Articles/gcEssentials.html >

- Ken

On Oct 3, 2009, at 4:10 AM, Nick Rogers wrote:

Hi,

I have a class as following:

@interface NodeTypeOrph : NSObject {
        int                             count;
        ItemTypeOrph    *key[4];   // Warning: indexing starts at 0, not 1
        NodeTypeOrph    *branch[5];   // Fake pointers to child nodes
}

when I'll send a release to an object of this type, will it automatically release the arrays of ItemTypeOrph and NodeTypeOrph objects.
Or do I have to explicitly traverse and release?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to