• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Does cocoa just leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

  • Prev by Date: Re: Does cocoa just leak?
  • Next by Date: Re: Does cocoa just leak?
  • Previous by thread: Re: Does cocoa just leak?
  • Next by thread: Re: Does cocoa just leak?
  • Index(es):
    • Date
    • Thread