• 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: NSObject Foundation tool memory issue?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSObject Foundation tool memory issue?


  • Subject: Re: NSObject Foundation tool memory issue?
  • From: Lee Cullens <email@hidden>
  • Date: Thu, 08 Dec 2005 18:05:26 -0500

Nick & Nico

Thanks to your suggestions I found what is causing the problem. I create and autorelease an object within the scope of the base pool. Then because I do so several times in one test loop iteration, the object's common print function (with a local pool) releases the object. So I am releasing an object in the base pool while within the scope of a local pool and I guess I've learned that is a no-no %-P (or maybe it's the combination of using release without a paired retain).

So if I remove the common release in the local pool scope and include it in the base pool scope (for each creation of the object opResult in a test iteration, after calling the common print function and before creating another opResult), instead of the prior Bus error I get:

objc: FREED(id): message release sent to freed object=0x3042e0
Trace/BPT trap

at the base pool release. This all begs the question of using [object release] at all with autoreleased objects (I know - my density is showing). Should I try to minimize my memory footprint with nested autorelease pools alone and forget about specific object releases? I suppose it's the mixing of the two that gets me in trouble - if I didn't initially autorelease the object then releasing it specifically would be alright. However, when the object is sometimes an operand and sometimes a result the simplest approach seemed to be autoreleasing it.

Anyway, a specific question. If I create-init-autorelease an object multiple times using the same variable, do I increase my memory footprint with the resulting unreferenced objects? That is:

opResult = newly created, initialized and autoreleased object
<some other processing using opResult>
opResult = newly created, initialized and autoreleased object
<some other processing using opResult>
opResult = newly created, initialized and autoreleased object

By the time I get to the third "opResult =" I have two unreferenced objects that would have been memory leaks before the advent of autoreleasePool. Does the autorelease mechanism decrement the retain count when I reuse the reference variable?

Thanks,
Lee C

PS: Sorry if I have gone on a bit too much, but sometimes thinking out-loud (trying to explain one's thinking) is much more productive than flailing around :-)


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: NSObject Foundation tool memory issue?
      • From: Scott Ellsworth <email@hidden>
    • Re: NSObject Foundation tool memory issue?
      • From: Nick Zitzmann <email@hidden>
References: 
 >NSObject Foundation tool memory issue? (From: Lee Cullens <email@hidden>)
 >Re: NSObject Foundation tool memory issue? (From: Niko Matsakis <email@hidden>)
 >Re: NSObject Foundation tool memory issue? (From: Lee Cullens <email@hidden>)
 >Re: NSObject Foundation tool memory issue? (From: Niko Matsakis <email@hidden>)
 >Re: NSObject Foundation tool memory issue? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Using an NSTextList
  • Next by Date: Re: NSObject Foundation tool memory issue?
  • Previous by thread: Re: NSObject Foundation tool memory issue?
  • Next by thread: Re: NSObject Foundation tool memory issue?
  • Index(es):
    • Date
    • Thread