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

Memory Mania Revisted


  • Subject: Memory Mania Revisted
  • From: email@hidden
  • Date: Thu, 7 Feb 2002 21:48:51 -0800

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...

Thanks in advance :-)

The not-as-hopeless-as-before Cocoa newbie
-Kevin Perry
_______________________________________________
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 Mania Revisted
      • From: John Hörnkvist <email@hidden>
    • Re: Memory Mania Revisted
      • From: Scott Anguish <email@hidden>
  • Prev by Date: Re: newbie question on 'Cocoa Programming for Mac OS X'
  • Next by Date: Drag and Drop: Carbon to Cocoa?
  • Previous by thread: Re: burning cd with cocoa
  • Next by thread: Re: Memory Mania Revisted
  • Index(es):
    • Date
    • Thread