• 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: Memory Mania Revisted
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Mania Revisted


  • Subject: Re: Memory Mania Revisted
  • From: Scott Anguish <email@hidden>
  • Date: Fri, 8 Feb 2002 01:25:13 -0500

nope.. no leak..

you're not changing the data in the pointer.. just the variable that points to that object... the autorelease pool will notice that you've not retained the values anywhere, and will chuck them next time it gets around to it..

unless you use an initSomething: method, or explicitly retain it, the autorelease mechanism should take care of it when it can (there are exceptions to this rule.. but that's pretty specific...)



On Friday, February 8, 2002, at 12:48 AM, email@hidden wrote:

Ok, I did a little reading up on memory allocation, release/retain
stuff, but I'm still a little bit confused about the specifics...

Here's some hypothetical code:

NSDecimalNumber *myDN = (NSDecimalNumber *)[NSDecimalNumber
numberWithFloat:2.5];
NSDecimalNumber *myOtherDN = (NSDecimalNumber *)[NSDecimalNumber
numberWithFloat:4.5];

// Suppose I want to take these two NSDecimalNumbers and add one to the
other like this:

myDN = [myDN decimalNumberByAdding:myOtherDN];

...

OK... I _think_ there's a leak here, because - (NSDecimalNumber
*)decimalNumberByAdding:(NSDecimalNumber *)dn creates a new instance of
NSDecimalNumber, right? then the original myDN memory is lost because
I've reassigned the pointer without deallocating this. My question is,
what is the best strategy for eliminating this leak? I do this step a
lot in my code, and I don't want to have to write 4 lines whenever I do
it...
_______________________________________________
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.

References: 
 >Memory Mania Revisted (From: email@hidden)

  • Prev by Date: Offscreen drawing again ...
  • Next by Date: Re: Memory Mania Revisted
  • Previous by thread: Memory Mania Revisted
  • Next by thread: Re: Memory Mania Revisted
  • Index(es):
    • Date
    • Thread