• 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: Leaks with Core-Data while fetching data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Leaks with Core-Data while fetching data


  • Subject: Re: Leaks with Core-Data while fetching data
  • From: Chris Hanson <email@hidden>
  • Date: Sun, 6 May 2007 05:03:37 -0700

On May 6, 2007, at 4:06 AM, Hell's KItchen Hell's KItchen wrote:

I'm working on a program that takes articles from the net and store
the relative index into a Core-Data persistent store. Unfortunatly
using OmniObjectMeter I've found a leak (it consumes lots of memory
resources) in a function that search into the database for a
particular message and returns it.

"Consumes a lot of memory" and "a leak" are very different things. A "leak" is memory that is consumed and never reclaimed. Is this memory never reclaimed even after your operation is complete, or does it just require an enormous amount of memory before it finishes?


As we suggested on #macdev, you should try wrapping this work in a periodically-released autorelease pool to keep your heap's high-water mark from rising too much. E.g., something like this:

  - (void)whatever {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
      int operations = 0;

      while (hasWorkToDo) {
          // real work here

          if ((operations++ % 10) == 0) {
              [pool release];
              pool = [[NSAutoreleasePool alloc] init];
          }
      }

      [pool release];
  }

This is a common pattern in Cocoa applications that do a lot of work but don't want to raise their heap's high-water mark too much.

This function is called lots of time when the program downloads
messages (it uses this function in order to link a messages with
another).

You might also want to consider separating the downloading of messages from the linking of messages together. Doing a fetch per message downloaded is very inefficient; you'll likely be better off putting off the linking to a separate stage, after you have all of the messages downloaded. That will allow you to have more flexibility in how you structure the fetch, for example; you could fetch all messages that you want to link to message 1234 at once, for example, rather than performing that fetch N times, once for each message that links to message 1234.


I've unsuccessfully tried to add an autorelease pool.

What was unsuccessful about it? Did you follow the pattern above? Did it crash, or just not help?


  -- Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >Leaks with Core-Data while fetching data (From: "Hell's KItchen Hell's KItchen" <email@hidden>)

  • Prev by Date: Leaks with Core-Data while fetching data
  • Next by Date: Re: Document init
  • Previous by thread: Leaks with Core-Data while fetching data
  • Next by thread: Leaks with Core-Data while fetching data
  • Index(es):
    • Date
    • Thread