Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does cocoa just leak?



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


References: 
 >Re: Does cocoa just leak? (From: Rosyna <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.