Re: Does cocoa just leak?
Re: Does cocoa just leak?
- Subject: Re: Does cocoa just leak?
- From: Fabrice Truillot <email@hidden>
- Date: Sun, 30 Sep 2001 07:10:12 +0200
On Dimanche, septembre 30, 2001, at 06:26 , Rosyna wrote:
>
And why isn't all the strings released when awakeFromNib is over
>
when an Auto release pool is not explicitly declared?
http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/
MemoryMgmt/index.html
Cocoa has some memory management policies you should now.
"Ideally a body of code should never be concerned with releasing
something it didn't create. Cocoa therefore sets this policy: If
you create an object (using alloc or allocWithZone:) or copy an
object (using copy, copyWithZone:, mutableCopy, or
mutableCopyWithZone:), you alone are responsible for releasing it.
If you didn't directly create or copy the object, you don't own it
and shouldn't release it."
[[instance URL] path] possibly creates 2 temporary instances
(NSURL & NSString ?), autoreleased with the active
NSAutoreleasePool.
[[NSFileManager defaultManager] // returns an autoreleased NSFileManager
fileExistsAtPath:
[[instance URL] // another autoreleased instance (NSURL)
path]]; // and now : an autoreleased NSString
When the active NSAutoreleasePool is released, theses instances
will be recycled. Without an active NSAutoreleasePool, the memory
will leaks...
[NSAutoreleasePool showPools]; shows the state of the current
NSAutoreleasePools (for the current thread). Try it !
-- FT'e