• 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
Memory management question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory management question


  • Subject: Memory management question
  • From: Randall Meadows <email@hidden>
  • Date: Wed, 24 Mar 2004 12:40:09 -0500

I need to see if I "get" ObjC's memory management scheme yet:

I have a method that returns an autoreleased NSString*; in an instance of a class I store that returned value in an ivar; I then store that class instance in an NSArray.

Putting the class instance into the array increases its (the class instance) refcount, right? What about the refcount of the NSString ivar contained in that class? Not touched, right? I have to explicitly retain/release that, correct? What's the easiest way to managed that--"retain" in my setter method and override "-dealloc" in my class and release the NSString* ivar there?

What about something like:

line = [line stringByTrimmingCharactersInSet:...];

where line is also an autoreleased NSString*? Since the "line" on the RHS is already in an autorelease pool, it'll get released when the pool does its thing, right? And then the new value assigned to the lvalue "line" gets autoreleased (eventually), right?

I have a feeling I'm going to get quite the memory management education when I finally let my nested loops run at full tilt--each is bounded by a custom NSAutoreleasePool; I'm hoping to shortcut that a bit by learning from the masters around here...
_______________________________________________
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.


  • Follow-Ups:
    • Re: Memory management question
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: Preference panes
  • Next by Date: Re: NSTableView setDoubleAction:
  • Previous by thread: Re: memory management question
  • Next by thread: Re: Memory management question
  • Index(es):
    • Date
    • Thread