From: Steven_Lord on


"Ferry " <frietje44(a)hotmail.com> wrote in message
news:i294c3$t1$1(a)fred.mathworks.com...

*snip*

> I'm still struggling with this problem. If I add the line:
> length(findall(gca, 'Type', 'image')) to my code, the value returned
> always equals 0.
> This is strange as there are more images in my window.
> I also tried Jan's suggestion: length(findobj(FigureHandle)), with my own
> image handle in it, which keeps returning 1.
>
> I even tried length(allchild(gca)), which returns 20 all the time. So
> apparently the memory leak doesn't occure because of adding images?
>
> Any suggestions left? Or are there possible tests to see what the memory
> is filled with?

I think we'll need to see a full piece of code (that we can run) with which
you can reproduce this behavior in order to have any chance at locating the
cause of this problem. I suggest you send it to Technical Support in
addition to or instead of the newsgroup.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: Jan Simon on
Dear Ferry,

> I'm still struggling with this problem. If I add the line:
> length(findall(gca, 'Type', 'image')) to my code, the value returned always equals 0.

This means, that there is no image in your GCA -- but which AXES handle is returned by GCA? Is this the only axis object in your figure? Perhaps you create an extra axis for each new image and GCA is a different object?

> This is strange as there are more images in my window.
> I also tried Jan's suggestion: length(findobj(FigureHandle)), with my own image handle in it, which keeps returning 1.

The command displays the number of all (unhidden) objects inside the figure, if you use the handle of the figure. But if you use the handle of the image, you find this image only. Please use the figure handle for "FigureHandle" -- therefore I've chosen this unequivocal name of the variable!

> I even tried length(allchild(gca)), which returns 20 all the time.
> So apparently the memory leak doesn't occure because of adding images?

Again: GCA is most likely not the needed object. Try "allchild(FigureHandle)" or if you are sure, that there is only one figure open, try "allchild(gcf)".

In addition you can count the number of AXES objects:
disp(length(findobj(allchild(gcf), 'type', 'axes')))
Or stop the loop after 20 iterations and start the property inspector.

Good luck, Jan
From: Ferry on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i29pun$prm$1(a)fred.mathworks.com>...
> Dear Ferry,
>
> > I'm still struggling with this problem. If I add the line:
> > length(findall(gca, 'Type', 'image')) to my code, the value returned always equals 0.
>
> This means, that there is no image in your GCA -- but which AXES handle is returned by GCA? Is this the only axis object in your figure? Perhaps you create an extra axis for each new image and GCA is a different object?
>
> > This is strange as there are more images in my window.
> > I also tried Jan's suggestion: length(findobj(FigureHandle)), with my own image handle in it, which keeps returning 1.
>
> The command displays the number of all (unhidden) objects inside the figure, if you use the handle of the figure. But if you use the handle of the image, you find this image only. Please use the figure handle for "FigureHandle" -- therefore I've chosen this unequivocal name of the variable!
>
> > I even tried length(allchild(gca)), which returns 20 all the time.
> > So apparently the memory leak doesn't occure because of adding images?
>
> Again: GCA is most likely not the needed object. Try "allchild(FigureHandle)" or if you are sure, that there is only one figure open, try "allchild(gcf)".
>
> In addition you can count the number of AXES objects:
> disp(length(findobj(allchild(gcf), 'type', 'axes')))
> Or stop the loop after 20 iterations and start the property inspector.
>
> Good luck, Jan


Thx for your reply Jan!

Indeed it seems that the figure uses 3 axes. So that was probably one of the issues.
Sorry, missed the point of using the 'figure' handle. With allchild(gcf), or even with allchild(figurehandle) it returns numbers close to 2000. However, the number doesn't grow when running my loop. So it really seems that the memoryleak is caused by something else. Unfortunately I cannot post the whole code, because it mainly isn't my property. I will try to create a small program which produces the same error and will let you know if I know more.

Thx for your help!
From: Jan Simon on
Dear Ferry,

> Indeed it seems that the figure uses 3 axes. So that was probably one of the issues.
> Sorry, missed the point of using the 'figure' handle. With allchild(gcf), or even with allchild(figurehandle) it returns numbers close to 2000.

3 axes, but the figure has and 2000 children?
Be aware, that "allchild(figurehandle)" replies the children only, not the grandchildren and their relatives. So if you have 1997 children, which are no axes objects, this might polute your memory already.

How many children replies "length(findall(FigureHandle))"? Is this number growing?

Jan
From: Ferry on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i2c4iv$lnb$1(a)fred.mathworks.com>...
> Dear Ferry,
>
> > Indeed it seems that the figure uses 3 axes. So that was probably one of the issues.
> > Sorry, missed the point of using the 'figure' handle. With allchild(gcf), or even with allchild(figurehandle) it returns numbers close to 2000.
>
> 3 axes, but the figure has and 2000 children?
> Be aware, that "allchild(figurehandle)" replies the children only, not the grandchildren and their relatives. So if you have 1997 children, which are no axes objects, this might polute your memory already.
>
> How many children replies "length(findall(FigureHandle))"? Is this number growing?
>
> Jan

length(findall(FigureHandle)) returns 352 and remains constant.

Sorry for my late reply, but the computer the software is running on, is at my university. And since i'm not there every day, I cannot test all the time.

Unfortunately the problem seems to be somewhere in the codepart which isn't mine. I created a stripped down version of the whole project which does actually everything in the same manner, but this doesn't produce the memory leak.

This looks like this. I run the m-file start.m:
figure;
picture = struct('number1', 0, 'number2', 666);
picture.handle = image(rand(640,480,3));
drawnow;
sim('ImageTest');

ImageTest is a simulink model with only an m-file function block in it and it calls the following m-file 15 times a second with the struct picture as input.
Update.m:
function update(data)
hold on
I = GiveFrame(1);
set(data.handle, 'Cdata', I);
drawnow;


As noted before, this project works the same way the complex project does, but this one doesn't produce the memory leak. Unfortunately I cannot give you the original code. Seems like I will have to go through their code myself...

Ferry