Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Jun 25, 2017 8:57 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How do I clear the memory leak when loading pic in Loop
PostPosted: Wed Apr 04, 2012 9:42 pm 
Offline

Joined: Sun Jan 23, 2011 11:59 am
Posts: 465
This is a subset of my codes basically I narrowed down to this

dim noofpic as integer
dim picfile as folderitem
noofpic = listbox1.listcount-1
dim p as picture

label1.text = "Enjoy the Show"
for y as integer = 0 to noofpic

p = new picture(324,286,32)

picfile = getfolderitem(listbox1.cell(y,0),folderitem.PathTypeShell)

p = picture.Open(picfile)
imagewell1.image = p
imagewell1.Invalidate

for wait as integer = 0 to 10000
// wait
next

imagewell1.image = nil

next

label1.Text = "Done"


Basically, what I am just doing here is looping through the photos from a Listbox and showing it in an ImageWell, actually it does not matter if I load it to the imagewell or not. What happens is that the under Activity Monitor, the Real Memory Usage just goes and grows even after the loop is complete, it is still not released. When I start the loop again, the memory usage grows.

I try looking around but do not see anywhere I could use to free this memory. In my actual app, the memory can swell to over 1.6gb and then it exhibits weird behavior like global variables starts to be set to nil.

Is this a bug or I am missing up somewhere on memory management ?

I only tested in Cocoa and Carbon and both shows the same issues in Real Studio 2011 R4.3

Thanks for any help.

_________________
RealStudio 2012R1 ♡ Macbook Pro Mac OS X 10.8.1 Moutain Lion
http://www.batchimage.com


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 12:04 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Not positive here... but I don't think you need the line that says

p = new picture(324,286,32)

This allocates a buffer area for a picture.... but then the next line

p = picture.Open(pic file)

Allocates the one the picture actually goes in.... and since you never set the first one to NIL... it stays allocated ... until it goes out of scope.. which isn't until the end of your procedure....

I might even try this instead

imagewell1.image = picture.Open(pic file)

and remove ALL references to "p"

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 12:07 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Sounds like a bug. In fact, I think there was one reported recently. Check Feedback.

p = picture.Open(pic file)

This *should* destroy the previously allocated picture object, so while
p = new picture(324,286,32)

is extraneous, it shouldn't cause any memory issues. If you remove it, you will leak memory more slowly, but it shouldn't be leaking at all.


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 12:32 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
timhare wrote:
p = picture.Open(pic file)

This *should* destroy the previously allocated picture object

I've done precisely this quite a lot and it is destroyed.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 12:59 am 
Offline

Joined: Sun Jan 23, 2011 11:59 am
Posts: 465
I've modified the codes to

dim noofpic as integer
dim picfile as folderitem
noofpic = listbox1.listcount-1
dim p as picture

for y as integer = 0 to noofpic

picfile = getfolderitem(listbox1.cell(y,0),folderitem.PathTypeShell)
p = picture.open(picfile)
imagewell1.image = p
imagewell1.Invalidate
p = nil

for wait as integer = 0 to 10000
// wait
next

imagewell1.image = nil

next


I modified the codes to the above and it is still leaking. I tried without using p but for some weird reason, the app crashed. I think it was to do with the color space or something to that nature.

The leak seems to be pretty much the same. It looks like 'nil' doesn't seems to do anything. Only when the entire thread ends that the memory goes back to the pre-execution stage.

Apart from allocating 'nil' is there anything which I should be doing to free the memory ?

_________________
RealStudio 2012R1 ♡ Macbook Pro Mac OS X 10.8.1 Moutain Lion
http://www.batchimage.com


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 1:29 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
No. You shouldn't even need to set it to nil.


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 2:31 am 
Offline

Joined: Sun Jan 23, 2011 11:59 am
Posts: 465
Thanks. I posted this codes to Feedback 18572. I guess there is nothing much I could do apart from waiting for RS to plug the leak.

_________________
RealStudio 2012R1 ♡ Macbook Pro Mac OS X 10.8.1 Moutain Lion
http://www.batchimage.com


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 8:34 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Another guess here.......
but try putting the DIM statement INSIDE the loop...

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Thu Apr 05, 2012 4:33 pm 
Offline

Joined: Sun Jan 23, 2011 11:59 am
Posts: 465
DaveS wrote:
Another guess here.......
but try putting the DIM statement INSIDE the loop...


Thanks. I tried the following

dim noofpic as integer

noofpic = listbox1.listcount-1


for y as integer = 0 to noofpic
dim p as picture
dim picfile as folderitem
picfile = getfolderitem(listbox1.cell(y,0),folderitem.PathTypeShell)
p = picture.open(picfile)
imagewell1.image = p
imagewell1.Invalidate
p = nil

for wait as integer = 0 to 10000
// wait
next

imagewell1.image = nil

next


But it does not seems to do anything to reduce the memory. It did however clear when the thread ended. I guess it is probably a real memory leak.

_________________
RealStudio 2012R1 ♡ Macbook Pro Mac OS X 10.8.1 Moutain Lion
http://www.batchimage.com


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Fri Apr 06, 2012 3:50 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Technically, its only a leak if the memory doesn't come back.
Since you reckon it does when the process ends, maybe its a good idea to split this into chunks.

First, add a timer to the window, set to fire every few seconds.
Add an integer property (called lstPlace) to the window, to record 'place in the listbox'

Now, in the timer's event, do this:

if lstPlace < listbox1.listcount-1 then
lstPlace +1
end if
imagewell1.image = picture.open(getfolderitem(listbox1.cell( lstPlace,0), folderitem.PathTypeShell))
imagewell1.Invalidate


So there are no intermediary images: just the one 'owned' by the image well
And everything goes out of scope at the end of the timer event, so garbage collection should kick in.


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Fri Apr 06, 2012 4:05 am 
Offline

Joined: Mon Feb 07, 2011 2:49 pm
Posts: 13
Hello

Image handling in RB is pretty broken, the from data method leaks too (but not in carbon).

viewtopic.php?f=7&t=41225&p=229353#p229353

Goldmagnet

_________________
http://www.icode.co.uk/icatcher
Hybrid CCTV Software


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Fri Apr 06, 2012 5:25 am 
Offline

Joined: Sun Jan 23, 2011 11:59 am
Posts: 465
I actually did experiment with breaking up the list into several chunks with each for next loop handling not more than 50 images. But the memory was not release until the last loop is completed. I used the sleepmbs in between those loops, thinking that the system with have some time to do its memory management.

Actually the whole process I wanted to achieve were to resize the images and adding some effects from Einhugur to the images before saving them. Whether I display the images or not, it does not actually make a difference to the memory usage.

_________________
RealStudio 2012R1 ♡ Macbook Pro Mac OS X 10.8.1 Moutain Lion
http://www.batchimage.com


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Fri Apr 06, 2012 2:02 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
eddy2099 wrote:
I actually did experiment with breaking up the list into several chunks with each for next loop handling not more than 50 images. But the memory was not release until the last loop is completed. I used the sleepmbs in between those loops, thinking that the system with have some time to do its memory management.

But that really doesn't separate them if they're still in the same method chain. Try the timer idea, that creates true separation.


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Fri Apr 06, 2012 5:15 pm 
Offline

Joined: Sun Jan 23, 2011 11:59 am
Posts: 465
timhare wrote:
But that really doesn't separate them if they're still in the same method chain. Try the timer idea, that creates true separation.


Thanks.

I tried these

Window1 Control Timer1:
Sub Action()
if nowpic < noofpic+1 then
dim p as picture
dim picfile as folderitem
picfile = getfolderitem(listbox1.cell(nowpic,0),folderitem.PathTypeShell) p = picture.open(picfile)
imagewell1.image = p
imagewell1.Invalidate
nowpic = nowpic+1
timer1.enabled = true
else
timer1.enabled = false
end if
End Sub


But the memory usage till keeps going up.

_________________
RealStudio 2012R1 ♡ Macbook Pro Mac OS X 10.8.1 Moutain Lion
http://www.batchimage.com


Top
 Profile  
Reply with quote  
 Post subject: Re: How do I clear the memory leak when loading pic in Loop
PostPosted: Sat Jun 01, 2013 4:18 pm 
Offline

Joined: Tue Aug 07, 2012 9:46 pm
Posts: 26
Did you ever find a solution to this? I am running into the same thing with 12 r2.1 when using cocoa. Doesn't release the memory like it should even if you nil it out.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group