Sorry about any confusion that I may have caused! The color I got from the NSGradient's -getColor:location:atIndex: actually was autoreleased, but the NSGradient was not. Therefore, the color always had an retain count of 1.

Sorry about that.


If you are trying to find a leak, then use one of the tools on the system designed for exactly that -- leaks, Object Graph in Instruments for GC, Object Alloc for non-GC, etc...

I didn't try to find a leak with this NSGradient method, I tried to find a rule of thumb for the memory management for objects created and returned by reference. Apart from NSNetService's - getInputStream:outputStream: and NSGradient's - getColor:location:atIndex:, I couldn't find such a case (there are plenty of methods returning primitives or C-structs by reference, though). Now that I think of it, any method using an NSError** might be worth looking into: In this case, the basic memory management rules apply. The Error Handling Programming Guide is clear about this:

[...] you should send autorelease to [the NSError object] before you return it to the caller.

http://developer.apple.com/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/chapter_4_section_4.html


Now... in this particular case...

How can you look at the retain count of an object after the autorelease pool was drained without it being retained by something? Didn't you have to retain it to keep the NSColor iVar around?


I just made an NSColor ivar and retained it after calling - getColor:location:atIndex: and took a look on its retain count in a second method that was called after the NSAutoreleasePool had been drained (i.e. I took a look at the retain count after pressing a button). That way, all -autorelease messages must have been dealt with and what remains are the "real" retains.
_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to