Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
GUI + timer based app really slows down machine

Subject: GUI + timer based app really slows down machine

From: Verma

Date: 11 Aug, 2010 08:02:06

Message: 1 of 7

Hi all,

We have developed an Matlab app which when launched, keeps slowing down
the machine so much so that we need to kill Matlab or even restart the machine
in a couple of hours.

Following is a brief description of our app's architecture:
1. We use timers to periodically (~ 30 sec) update various graphs on GUI.
2. Most timer callback functions use persistent variables to keep the state.
3. We connect and disconnect to kdb database using a java library every time
    a timer call back function needs to update the GUI.
4. Data retrieved on every time is < 5000 rows and 10 columns takes under 1 sec.

The app slows down events like tab switching in an hour or so, and in several hours
slows down everything on the PC.

Will be a great help if someone can point us in some directions we can explore.

Regards,
Sid

Subject: GUI + timer based app really slows down machine

From: Jan Simon

Date: 11 Aug, 2010 11:37:05

Message: 2 of 7

Dear Verma,

the information you gave is not sufficient to identify the problem. You can use the PROFILEr to see, where the time is lost. I guess, that you draw some diagrams or create some figure in each iteration without deleting the old ones. Then Matlab is exhausted with displaying millions of objects?
Does the java-base connection to the database consume head-memory without freeing it afterwards?

Kind regards, Jan

Subject: GUI + timer based app really slows down machine

From: Yair Altman

Date: 11 Aug, 2010 14:52:04

Message: 3 of 7

It is possible that you have a memory leak in your system. The leak can be caused by the GUI objects and/or the Java code. If the leak is large enough, your computer will start to slow down when the physical memory is exhausted and your Operating System starts to use swap (disk) space for memory management.

To determine whether this is indeed the issue, download and use Microsoft's Process Explorer utility from www.sysinternals.com - by clicking the Matlab process you will be able to see a graph of the actual memory used by Matlab over time.

You can also use the built-in Matlab Profiler, if you use the undocumented memory-profiling options as explained here: http://undocumentedmatlab.com/blog/undocumented-profiler-options/ . The Profiler is helpful, but I am skeptical if you will find memory leaks using it.

Yair Altman
http://UndocumentedMatlab.com

Subject: GUI + timer based app really slows down machine

From: Verma

Date: 12 Aug, 2010 10:06:05

Message: 4 of 7

Yair,

Thanks a ton for your suggestions. Process explorer gave a lot of useful information.
I am clearly able to see that number of GDI handles and User Handles keeps growing
with time (reaches 9000 in 3 hrs). Memory itself is not growing so much (~300 MB, while 1.5 GB is unused).

But I am clearing all axes (cla) before redrawing new graphs. Any guesses on why
handles may be growing with time?
Regards,
Siddharth

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <i3udek$bl1$1@fred.mathworks.com>...
> It is possible that you have a memory leak in your system. The leak can be caused by the GUI objects and/or the Java code. If the leak is large enough, your computer will start to slow down when the physical memory is exhausted and your Operating System starts to use swap (disk) space for memory management.
>
> To determine whether this is indeed the issue, download and use Microsoft's Process Explorer utility from www.sysinternals.com - by clicking the Matlab process you will be able to see a graph of the actual memory used by Matlab over time.
>
> You can also use the built-in Matlab Profiler, if you use the undocumented memory-profiling options as explained here: http://undocumentedmatlab.com/blog/undocumented-profiler-options/ . The Profiler is helpful, but I am skeptical if you will find memory leaks using it.
>
> Yair Altman
> http://UndocumentedMatlab.com

Subject: GUI + timer based app really slows down machine

From: Aleksandar Stojimirovic

Date: 12 Aug, 2010 10:07:06

Message: 5 of 7

Hallo, see this

http://www.mathworks.com/matlabcentral/newsreader/view_thread/289128

maybe it can help you, and maybe you have some idea to improve my code!!!

Subject: GUI + timer based app really slows down machine

From: Jan Simon

Date: 12 Aug, 2010 12:34:24

Message: 6 of 7

Dear Verma,

> I am clearly able to see that number of GDI handles and User Handles keeps growing
> with time (reaches 9000 in 3 hrs). Memory itself is not growing so much (~300 MB, while 1.5 GB is unused).
>
> But I am clearing all axes (cla) before redrawing new graphs. Any guesses on why
> handles may be growing with time?

It seems like you create the objects not in the current axes object, which is cleared by CLA. Perhaps you create a new AXES in each iteration?
However, this cannot be answered by the newsgroup, but by your debugger. Go to your program step by step and look, where objects are created and deleted. Search for all created axes:
  findall(gcf, 'type', 'axes')

Kind regards, Jan

Subject: GUI + timer based app really slows down machine

From: Yair Altman

Date: 12 Aug, 2010 16:42:04

Message: 7 of 7

> I am clearly able to see that number of GDI handles and User Handles keeps growing
> with time (reaches 9000 in 3 hrs). Memory itself is not growing so much (~300 MB, while 1.5 GB is unused).
>
> But I am clearing all axes (cla) before redrawing new graphs. Any guesses on why
> handles may be growing with time?

This happens because the GUI handles are not deleted properly. Perhaps you leave a trail of handle references without clearing/deleting them, and perhaps due to some internal Matlab bug.

In any case, instead of clearing the axes and other GUI handles, try to reuse them by simply modifying their properties. This will both improve performance and reduce the number of newly-created GDI handles.

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us