• 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: Some Questions...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some Questions...


  • Subject: Re: Some Questions...
  • From: Jerry LeVan <email@hidden>
  • Date: Sun, 20 Jun 2004 12:55:37 -0400

Gus Muller tipped me to this: ( Your Point 2)

for(i=0 ; i< fcnt ; i++) {
// NSImage * tmp= [[NSImage alloc]initWithContentsOfFile:(NSString*)[fileNameList objectAtIndex:i]];
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSImage * tmp = [self altMakeThumb:[fileNameList objectAtIndex:i]];
[[thumbArray cellAtRow:i column:0] setImage: tmp];
[[thumbArray cellAtRow:i column:0] setTarget:self];
[[thumbArray cellAtRow:i column:0] setAction:@selector(showMe:)];
[tmp release];
[filesLeft setIntValue: fileCtr--];
[filesLeft displayIfNeeded];
[pool release];
}

The addition of the auto release pool in the loop, and its
subsequent release at the bottom made all of my memory usage problems go
away :) (I did not believe it until I "Read the Fine manual"...)

The function altMakeThumb creates a *small* image from the bigger image
via some voodoo that I don't completely understand yet...

The filesLeft stuff in the loop is for a progress display indicating the
number of files left to process. I was surprised that the "displayIfNeeded
was able to update the progress dialog event though I was in the
tight loop.

Jerry

On Jun 20, 2004, at 12:33 PM, matt neuburg wrote:

On Sat, 19 Jun 2004 22:45:54 -0400, Jerry LeVan <email@hidden> said:

The app can ask for a directory from a user, it then creates
a thumbnail of every graphic that the appkit understands and
displays them in a scrolling list. Clicking on a thumb causes
the image to be shown is a larger frame with a zoom slider
for controlling the size.

I am processing the thumbs in a "tight" loop. Watching "top" while
the program grinds away processing the images into thumbs I can
watch the VM size growth to over 1GIG, this slows things down as
swapping/paging activity increases.

After the thumbs are processed memory usage drops to a very acceptable
level.

I think the problem is that "released" images don't get claimed in
a timely manner...

***********
Is there a "simple" strategy for dealing with this problem? ( I have
yet to use threads in Cocoa...).
***********

My app does much the same thing so I had to grapple with the same memory
management issues. I presume (from the fact that you say memory usage drops
afterwards) that you are already using

fcntl(fd, F_NOCACHE, 1);
fcntl(fd, F_RDAHEAD, 1);

That was most of the battle for me right there. So, the only things I can
suggest after that are:

(1) Manage memory yourself as much as possible, i.e. don't make any calls in
your loop that generate auto-released objects; instead, use the alloc-init
type of call and release the objects manually. Just in case, though, also
make an NSAutoReleasePool at the start of your loop and release it at the
bottom of every iteration.

(2) Try to avoid using NSImage. You can open an image directly from disk as
an NSBitmapImageRep and often this is all you need. If you must use an
NSImage, recache it just before you release it.

(3) Use MallocDebug.

m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
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: Some Questions...
      • From: j o a r <email@hidden>
References: 
 >Re: Some Questions... (From: matt neuburg <email@hidden>)

  • Prev by Date: Checking For Keys
  • Next by Date: Custom buttons
  • Previous by thread: Re: Some Questions...
  • Next by thread: Re: Some Questions...
  • Index(es):
    • Date
    • Thread