Real Software Forums
http://forums.realsoftware.com/

How do I clear the memory leak when loading pic in Loop
http://forums.realsoftware.com/viewtopic.php?f=1&t=43478
Page 2 of 2

Author:  MikeD [ Sat Jun 01, 2013 10:19 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

I have exactly this issue ... and posted a question in this forum a few days ago with the title

"Memory used for graphics - Carbon vs Cocoa"

Memory will free up when the loop is done ... but before that happens if I'm processing alot of picture files (or large picture files) it crashes with an out of memory error before it finishes.

All ok in carbon, not so in cocoa.

I can avoid the problem by opening the file in the paint event rather than opening the file and setting the picture to each canvas backdrop ... but if I have alot of indexed canvases (for thumbnails) it slows down scrolling alot by firing the paint event on a boatload of canvases on every scroll move or window resize.

I sure hope this gets fixed with next week's release ... and glad to know I'm not the only person experiencing it.

Author:  lajdesign [ Sat Jun 01, 2013 10:30 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

In my case I am watermarking images and you can just watch the memory leak. I can nil out the picture, but it still leaks until the method is done.

Author:  tomis [ Sun Jun 02, 2013 1:45 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

MikeD wrote:
Memory will free up when the loop is done


What happens if you move the looping outside the method, then call the method from a thread, or better yet use a timer?

With a timer:
* Use an outside variable to keep track of your position in the list.
* The timer calls the method
* When the method is complete it increments the variable, then sets up the timer to call it again: timer.period=1, timer.mode=1

Author:  lajdesign [ Sun Jun 02, 2013 2:51 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

I went the easy route and moved the picture variable from inside the method to outside. That fixed the issue, the memory was released as it should be.

Before it would hit 2 gigs in memory and now didn't go over 200 meg. Thanks for the ideas.

Luke

Author:  taylor-design [ Sun Jun 02, 2013 2:59 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

lajdesign wrote:
I went the easy route and moved the picture variable from inside the method to outside. That fixed the issue, the memory was released as it should be.

Before it would hit 2 gigs in memory and now didn't go over 200 meg. Thanks for the ideas.


So if you use a property in a module (for example) then there's no leak?

Author:  lajdesign [ Sun Jun 02, 2013 3:30 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

Never mind. I forgot I had swapped to carbon. I will try some of the other things later. I hate tons of extra work around a very clear bug. Still leaks horribly in cocoa.

Author:  MikeD [ Sun Jun 02, 2013 5:16 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

tomis wrote:
MikeD wrote:
Memory will free up when the loop is done


What happens if you move the looping outside the method, then call the method from a thread, or better yet use a timer?

With a timer:
* Use an outside variable to keep track of your position in the list.
* The timer calls the method
* When the method is complete it increments the variable, then sets up the timer to call it again: timer.period=1, timer.mode=1


Well I'll be darned. Some success here. The main purpose of the method is the loop ...but I simply moved the "picture.open" to a thread that's fired off by the method. In the thread all I do is open the picture from a file and save it to a temporary property of the main window, then the method continues by picking up the picture from the property and goes ahead with the rest of the code. A little messy, but it seems to work.

Still ... I hope things speed up with cocoa. In carbon I can open a folder of 800 small jpegs (average 200kb each) and make and display thumbnails ... all in 20 seconds or less. In cocoa it takes about a minute.

Author:  lajdesign [ Sun Jun 02, 2013 9:53 pm ]
Post subject:  Re: How do I clear the memory leak when loading pic in Loop

Seems to work here also. Not as fast, but doesn't leak. I wish cocoa would be faster, but I just want it to work for the app store.

Page 2 of 2 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/