Path: news.mathworks.com!not-for-mail
From: "helper " <spamless@nospam.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Callback Cross close function
Date: Tue, 13 May 2008 16:21:04 +0000 (UTC)
Organization: Timothy S. Farajian, Inc.
Lines: 37
Message-ID: <g0cf5g$45e$1@fred.mathworks.com>
References: <g0cb3g$17m$1@fred.mathworks.com>
Reply-To: "helper " <spamless@nospam.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210695664 4270 172.30.248.38 (13 May 2008 16:21:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 May 2008 16:21:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1272923
Xref: news.mathworks.com comp.soft-sys.matlab:468191


"Luca Cerone" <cerone@to-see.it> wrote in message 
<g0cb3g$17m$1@fred.mathworks.com>...
> Hi,
> I'm developing a compiled GUI application.
> It works fine, but I have a problem:
> I can't succeed in making the program to free memory when 
i
> close it clicking on the X (cross) button of my 
application.
> 
> How can I write a callback for the X button?
> How can I deallocate all memories, destroy all classes and
> free memory (is a clear all enough before of returning?)
> If you could help me, I would be very grateful!
> Thank you very much in advance!!! -Luca-

To start with, use the "CloseRequestFcn" of the figure to 
specify a callback function for whenever the figure is 
requested to close (including using the X button).  Note 
that at the end of this function, use the DELETE function 
to actually delete the figure.

As far as I know, CLEAR ALL is unnecessary to clear 
variables from memory.  Having the executable quit should 
be enough to handle this.

However, things such as timers, serial objects, and OOP 
classes need to be carefully considered during their 
creation to ensure the appropriate cleanup and deletion 
occurs during the "CloseRequestFcn".  I do not believe 
there is any command within MATLAB to automatically cleanup 
and delete everything.

Note that the method for "cleaning up" things which require 
it are well documented within MATLAB.  For example, check 
out the documentation for TIMER and SERIAL.  They both show 
the necessary "cleanup" steps.