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

Re: NSOperationQueue Memory Leak


  • Subject: Re: NSOperationQueue Memory Leak
  • From: "Michael Ash" <email@hidden>
  • Date: Thu, 7 Aug 2008 15:45:00 -0400

On Wed, Aug 6, 2008 at 9:38 AM, Mike Simmons <email@hidden> wrote:
> I have an audio application that processes numerous audio streams into
> ten-second clips, compresses the clips, and saves them to disk. Naturally, I
> wanted to move from single-threaded processing to multithreaded processing
> for the clip compression/writing. That was easily done using the
> NSOperationQueue and the NSInvocation classes, and it worked nicely, apart
> from a bad memory leak that I can't seem to eradicate. So I finally wrote a
> small test application to encapsulate what I was doing in the larger
> program, and it too has a leak -- a big one!
>
> The test application simply spawns 10000 threads whose sole job is to
> display "Hi, I am thread xx" on the console. It then sleeps and spawns 10000
> more. At the end of the run some 38 MB of  real memory has been used, and it
> never goes down.  (I'm not using garbage collection, but I think I'm doing
> things correctly with the autorelease pool.)
>
> Can someone tell me what I'm doing wrong?

Two things:

1) As others have already pointed out, you're managing your memory
incorrectly. This is the main problem, and they've covered it.

2) Expecting your "real memory" usage to decrease. I assume you're
using Activity Monitor or top. These tools display how much memory
your process has requested from the OS. However, requesting memory
from the OS is expensive. Often the allocator, when freeing memory,
will not return it to the OS, but instead just keep it so that it can
be reused for the next allocation. Having your memory usage in these
tools not go down can be a good warning sign (and having it increase
without limit is a definite problem) but you should use a dedicated
tool such as MallocDebug or ObjectAlloc to determine if you're leaking
and why.

Mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSOperationQueue Memory Leak (From: Mike Simmons <email@hidden>)

  • Prev by Date: Re: -[NSBrowser scrollToVisible] not making all of the column
  • Next by Date: Re: packed NSTextfield and NSFormatter in IB3 plugin...
  • Previous by thread: Re: NSOperationQueue Memory Leak
  • Next by thread: Re: NSOperationQueue Memory Leak
  • Index(es):
    • Date
    • Thread