• 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: [Newbie Q] Memory Management in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Newbie Q] Memory Management in Cocoa


  • Subject: RE: [Newbie Q] Memory Management in Cocoa
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Tue, 5 Nov 2002 14:32:42 -0500

> Hi All,
>
> I'm getting a little bit confused about when to dealloc an instance.
> It's obvious that instances created like [[foo alloc] init ]; should be
> deallocated when done with.
> But what about instances created like:
> NSString * aNSString = [NSString stringWithCString:"Hello" length:5];
>

Never call dealloc yourself. I think you meant release.

You should not release the string in your example. Class methods (e.g.,
most of the "With" methods for NSString and NSArray) return autoreleased
instances. Your string will be released at the end of the code block.
Usually this means the retainCount drops to zero and the object is dealloced
automagically. If you don't want that to happen, retain the object.

Instances you create with init or copy stick around until explicitly
released (or autoreleased and the pool gets released) and their retainCount
goes to zero.

Check out the memory management articles at stepwise.com.

Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: [Newbie Q] Memory Management in Cocoa
  • Next by Date: Re: [Newbie Q] Memory Management in Cocoa
  • Previous by thread: Re: [Newbie Q] Memory Management in Cocoa
  • Next by thread: Re: [Newbie Q] Memory Management in Cocoa
  • Index(es):
    • Date
    • Thread