<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Understanding Object Cleanup</title>
	<atom:link href="http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 16 Feb 2012 04:40:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Jerry Gregoire</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-31873</link>
		<dc:creator>Jerry Gregoire</dc:creator>
		<pubDate>Mon, 22 Nov 2010 22:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-31873</guid>
		<description>Thanks. Article helped a lot. Was unable to find the answer to stopping my timers till I stumbled onto your article.</description>
		<content:encoded><![CDATA[<p>Thanks. Article helped a lot. Was unable to find the answer to stopping my timers till I stumbled onto your article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt M. Sanger</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-31042</link>
		<dc:creator>Kurt M. Sanger</dc:creator>
		<pubDate>Fri, 29 Jan 2010 13:58:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-31042</guid>
		<description>Loren;  

Okay, call the figure setting &#039;visibility&#039; &#039;off&#039; and it won&#039;t pop up in front yet will return its handle.  But if it doesn&#039;t exist it will create a new instance.

Nick&#039;s method requires knowing the handle.  
&lt;pre&gt;get(hMyFig, &#039;Visible&#039;)

&lt;/pre&gt;

Using findobj with or without visibility returns an empty answer.
&lt;pre&gt; hiddenFigs = findobj(&#039;Type&#039;,&#039;figure&#039;,&#039;-and&#039;,&#039;Visible&#039;,&#039;off&#039;)

&lt;/pre&gt; 


I was only able to get findobj to work if I pass it the handles, which I don&#039;t know unless you call the gui and then if the gui wasn&#039;t open it creates a new instance.
&lt;pre&gt; object_handles = findall(handle_list)

&lt;/pre&gt; 
For now I&#039;ve created a gui that is always hidden, opens up all the others, and records their handles so that everyone can access the handles without invoking the individual guis.  This works unless I get an error that causes a hidden gui to quit.  Then weird things happen.  I think I can use findall or findobj to test for each gui before calling it or its sub-functions.</description>
		<content:encoded><![CDATA[<p>Loren;  </p>
<p>Okay, call the figure setting &#8216;visibility&#8217; &#8216;off&#8217; and it won&#8217;t pop up in front yet will return its handle.  But if it doesn&#8217;t exist it will create a new instance.</p>
<p>Nick&#8217;s method requires knowing the handle.  </p>
<pre>get(hMyFig, 'Visible')
</pre>
<p>Using findobj with or without visibility returns an empty answer.</p>
<pre> hiddenFigs = findobj('Type','figure','-and','Visible','off')
</pre>
<p>I was only able to get findobj to work if I pass it the handles, which I don&#8217;t know unless you call the gui and then if the gui wasn&#8217;t open it creates a new instance.</p>
<pre> object_handles = findall(handle_list)
</pre>
<p>For now I&#8217;ve created a gui that is always hidden, opens up all the others, and records their handles so that everyone can access the handles without invoking the individual guis.  This works unless I get an error that causes a hidden gui to quit.  Then weird things happen.  I think I can use findall or findobj to test for each gui before calling it or its sub-functions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Haddad</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30997</link>
		<dc:creator>Nick Haddad</dc:creator>
		<pubDate>Thu, 21 Jan 2010 20:27:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30997</guid>
		<description>Kurt,

Does your myFig() function call figure?  If it does then each call to myFig() will create a new figure.  

To simply reference your figure, use the hMyFig variable which is the handle to your figure.  

&lt;pre&gt;
% get the figure&#039;s visibility 
% without creating a new figure
myFigVisible = get(hMyFig, &#039;Visible&#039;);
&lt;/pre&gt;

As far as finding all hidden figures, you can use the the &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/findobj.html&quot; rel=&quot;nofollow&quot;&gt;findobj&lt;/a&gt; function to search for graphics objects with certain attributes:

&lt;pre&gt;
% find hidden figures
hiddenFigs = findobj(&#039;Type&#039;,&#039;figure&#039;,&#039;-and&#039;,&#039;Visible&#039;,&#039;off&#039;)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Kurt,</p>
<p>Does your myFig() function call figure?  If it does then each call to myFig() will create a new figure.  </p>
<p>To simply reference your figure, use the hMyFig variable which is the handle to your figure.  </p>
<pre>
% get the figure's visibility
% without creating a new figure
myFigVisible = get(hMyFig, 'Visible');
</pre>
<p>As far as finding all hidden figures, you can use the the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/findobj.html" rel="nofollow">findobj</a> function to search for graphics objects with certain attributes:</p>
<pre>
% find hidden figures
hiddenFigs = findobj('Type','figure','-and','Visible','off')
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30996</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 21 Jan 2010 20:13:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30996</guid>
		<description>Kurt-

When I do this:

&lt;pre class=&quot;code&quot;&gt;
h = figure(&#039;visible&#039;,&#039;off&#039;);
hh = figure(&#039;visible&#039;,&#039;off&#039;,&#039;handlevisibility&#039;,&#039;off&#039;);
get(h,&#039;visible&#039;)
get(hh,&#039;visible&#039;)
&lt;/pre&gt;

I get &#039;off&#039; as my answer to both get statements and no figures popping up.  I suspect you have more going on.  Please contact support with full details and they should be able to help you.

--Loren</description>
		<content:encoded><![CDATA[<p>Kurt-</p>
<p>When I do this:</p>
<pre class="code">
h = figure('visible','off');
hh = figure('visible','off','handlevisibility','off');
get(h,'visible')
get(hh,'visible')
</pre>
<p>I get &#8216;off&#8217; as my answer to both get statements and no figures popping up.  I suspect you have more going on.  Please contact support with full details and they should be able to help you.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt M. Sanger</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30995</link>
		<dc:creator>Kurt M. Sanger</dc:creator>
		<pubDate>Thu, 21 Jan 2010 19:40:51 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30995</guid>
		<description>Loren;  

Nice description of User Managed Objects.  I&#039;m working with guide, creating figures that are sometimes hidden.  I have two issues.  How to get the figure&#039;s handle or visible parameter when hidden without causing the figure to come to the front.  And how to find all hidden figures that haven&#039;t been deleted.

&lt;pre&gt;
hMyFig = myFig();  % returns a handle to myFig but also
                   % makes if visible and brings it to
                   % the front.

myFigVisible = get( myFig(), &#039;Visible&#039;); % Does the same.
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Loren;  </p>
<p>Nice description of User Managed Objects.  I&#8217;m working with guide, creating figures that are sometimes hidden.  I have two issues.  How to get the figure&#8217;s handle or visible parameter when hidden without causing the figure to come to the front.  And how to find all hidden figures that haven&#8217;t been deleted.</p>
<pre>
hMyFig = myFig();  % returns a handle to myFig but also
                   % makes if visible and brings it to
                   % the front.

myFigVisible = get( myFig(), 'Visible'); % Does the same.
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kieran Parsons</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30496</link>
		<dc:creator>Kieran Parsons</dc:creator>
		<pubDate>Thu, 30 Jul 2009 12:17:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30496</guid>
		<description>The very helpful Mathworks technical support team were able to help me out with #6. Their solution is posted at http://www.mathworks.com/support/solutions/en/data/1-ABQ59D/index.html if anyone is interested. An interesting use of strings in callbacks instead of anonymous functions.</description>
		<content:encoded><![CDATA[<p>The very helpful Mathworks technical support team were able to help me out with #6. Their solution is posted at <a href="http://www.mathworks.com/support/solutions/en/data/1-ABQ59D/index.html" rel="nofollow">http://www.mathworks.com/support/solutions/en/data/1-ABQ59D/index.html</a> if anyone is interested. An interesting use of strings in callbacks instead of anonymous functions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kieran Parsons</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30475</link>
		<dc:creator>Kieran Parsons</dc:creator>
		<pubDate>Fri, 17 Jul 2009 18:10:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-30475</guid>
		<description>I am trying to clean up a singleton GUI object (using a persistent variable as suggested in 2 and http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_oop/bru6n2g.html.) 

When the object is created I create a GUI figure window, and I want them to always exist as a pair. I have added a &#039;CloseRequestFcn&#039; callback that closes the figure and deletes the object if a user hits the close button. This works fine. However, I cannot figure out how to get the GUI figure to close if I clear the singleton object. I tried overloading the &#039;delete&#039; method(which normally works) but in the case of the clearing of a persistent object it seems that the &#039;delete&#039; method is not called.

Any ideas?

Thanks,
Kieran</description>
		<content:encoded><![CDATA[<p>I am trying to clean up a singleton GUI object (using a persistent variable as suggested in 2 and <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_oop/bru6n2g.html" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_oop/bru6n2g.html</a>.) </p>
<p>When the object is created I create a GUI figure window, and I want them to always exist as a pair. I have added a &#8216;CloseRequestFcn&#8217; callback that closes the figure and deletes the object if a user hits the close button. This works fine. However, I cannot figure out how to get the GUI figure to close if I clear the singleton object. I tried overloading the &#8216;delete&#8217; method(which normally works) but in the case of the clearing of a persistent object it seems that the &#8216;delete&#8217; method is not called.</p>
<p>Any ideas?</p>
<p>Thanks,<br />
Kieran</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: StephenLL</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-29635</link>
		<dc:creator>StephenLL</dc:creator>
		<pubDate>Wed, 30 Jul 2008 19:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-29635</guid>
		<description>Nick, Loren, Gautam:

Thank you for replying and your ideas.  I have a lot to learn and experiment with now.

I don&#039;t plan to make wide spread use of this technique for the obvious pitfalls like hidden dependence, but there is some functionality well served by it.

Thanks again.

Stephen</description>
		<content:encoded><![CDATA[<p>Nick, Loren, Gautam:</p>
<p>Thank you for replying and your ideas.  I have a lot to learn and experiment with now.</p>
<p>I don&#8217;t plan to make wide spread use of this technique for the obvious pitfalls like hidden dependence, but there is some functionality well served by it.</p>
<p>Thanks again.</p>
<p>Stephen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gautam Vallabha</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-29633</link>
		<dc:creator>Gautam Vallabha</dc:creator>
		<pubDate>Wed, 30 Jul 2008 16:41:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-29633</guid>
		<description>Another example of user-managed objects are graphics objects (FIGURE, AXES, PATCH, LINE, etc.). Nick&#039;s guidelines work for these as well:
1) There is a DELETE function for the graphics objects
2) There is a FINDALL function that can be used to catch all the HG objects, including those with visibility set to &#039;off&#039;.


With regard to Stephen&#039;s question: one guideline for building user-managed objects is to allow the user to assign a unique name to the object. This makes it easy to find them later. For example:

-----------
timer(&#039;period&#039;,0.25, &#039;name&#039;, &#039;myTimer&#039;);

% much later ... in some other function
h = timerfind(&#039;name&#039;, &#039;myTimer&#039;);
stop(h);
delete(h);
-----------

This strategy works with pretty much all user-managed objects in MATLAB.</description>
		<content:encoded><![CDATA[<p>Another example of user-managed objects are graphics objects (FIGURE, AXES, PATCH, LINE, etc.). Nick&#8217;s guidelines work for these as well:<br />
1) There is a DELETE function for the graphics objects<br />
2) There is a FINDALL function that can be used to catch all the HG objects, including those with visibility set to &#8216;off&#8217;.</p>
<p>With regard to Stephen&#8217;s question: one guideline for building user-managed objects is to allow the user to assign a unique name to the object. This makes it easy to find them later. For example:</p>
<p>&#8212;&#8212;&#8212;&#8211;<br />
timer(&#8216;period&#8217;,0.25, &#8216;name&#8217;, &#8216;myTimer&#8217;);</p>
<p>% much later &#8230; in some other function<br />
h = timerfind(&#8216;name&#8217;, &#8216;myTimer&#8217;);<br />
stop(h);<br />
delete(h);<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>This strategy works with pretty much all user-managed objects in MATLAB.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-29631</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 29 Jul 2008 17:27:03 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/07/29/understanding-object-cleanup/#comment-29631</guid>
		<description>Stephen-

If you do use persistent variables, you have to be careful about how multiple instances of the class work.  Today you have 2 more choices that don&#039;t limit you to a singleton pattern, nested functions or the object system introduced in R2008a.  There will be a blog on the latter coming soon.  In the meantime, check out the documentation on the class system.  

--Loren</description>
		<content:encoded><![CDATA[<p>Stephen-</p>
<p>If you do use persistent variables, you have to be careful about how multiple instances of the class work.  Today you have 2 more choices that don&#8217;t limit you to a singleton pattern, nested functions or the object system introduced in R2008a.  There will be a blog on the latter coming soon.  In the meantime, check out the documentation on the class system.  </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

