• 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: Why does this leak memory?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does this leak memory?


  • Subject: Re: Why does this leak memory?
  • From: Jamie Curmi <email@hidden>
  • Date: Sun, 19 Jan 2003 09:27:18 +1100

Hi Joar,

I really appreciate the help by the way.

I'll try and explain what I am trying to do. My application has a dock icon that is updated to reflect status in the application (it has a graphical count amongst other things).

What I originally was doing was to just retain the image as you suggested. However, I then modify that image by adding a count to it graphically. Then I set the application icon ([NSApp setApplicationIconImage:icon];).

Trouble is that next time I call [NSImage imageNamed:@"Connected"] I have the modifications as well, so numbers get drawn on top of numbers, and that messes up the icon.

So I decided what I really needed to do was make a copy of the [NSImage imageNamed:@"Connected"]. Then I modify that. I set the application icon image. And release the copy.

This does what I expect graphically, but there is a leak occurring in the process.

I figured maybe it was something to do with setting the application icon, or drawing the image. So, I've simplified it down to just the two lines I mailed about, and found that it appears the copy leaks with just the use of copy, followed by a release.

It isn't the [NSImage imageNamed:@"Connected"] which is leaking - as I've replaced that code with just that, and run it many times - no leaks. But when I make a copy, then release that copy, the leak occurs.

I believe I understand the reference counting and autorelease pool stuff - but maybe I'm missing something? But can someone explain why each call to that copy followed by release would leak more and more memory (not just the initial cached image for the imageNamed: call)?

Thanks.

Jamie

On Sunday, January 19, 2003, at 09:04 AM, j o a r wrote:

May I ask why you copy the item created in the first place? Why don't you simple:

[[NSImage imageNamed:@"Connected"] retain];

...if you want to keep the image created? By doing it the way you wrote in the first message, you'll immediately loose all references to the created image - and thus "leaking" it until it gets autoreleased - and only keep a reference to the copy.

It's not clear from your messages that you have understood the concept of reference counting and aboutorelease pools? Is that the problem, or is it really something else?

j o a r

On Saturday, Jan 18, 2003, at 22:32 Europe/Stockholm, Jamie Curmi wrote:

I should point out, every time this is called, more leaks occur. It isn't just the first call of [NSImage imageNamed:@"Connected"] that leaks (I realise that gets cached). It appears that every call of copy, followed by the release, ends up with more memory leaked.

MallocDebug shows the leak - and it increases with each call. Similarly "top" shows the vsize increasing with each call.
_______________________________________________
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: Why does this leak memory?
      • From: j o a r <email@hidden>
    • Re: Why does this leak memory?
      • From: Andreas Mayer <email@hidden>
    • Re: Why does this leak memory?
      • From: j o a r <email@hidden>
References: 
 >Re: Why does this leak memory? (From: j o a r <email@hidden>)

  • Prev by Date: Re: Why does this leak memory?
  • Next by Date: Warping an image with a Bezier Path
  • Previous by thread: Re: Why does this leak memory?
  • Next by thread: Re: Why does this leak memory?
  • Index(es):
    • Date
    • Thread