<br><br><div class="gmail_quote">On Fri, Jan 9, 2009 at 02:05, Tim Schaub <span dir="ltr">&lt;<a href="mailto:tschaub@opengeo.org">tschaub@opengeo.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hey-<br>
<div class="Ih2E3d"><br>
Erik Uzureau wrote:<br>
&gt; This is an interesting proposition.<br>
&gt;<br>
&gt; I have wanted for a long time to reform the way we do destroy().<br>
&gt; Specifically<br>
&gt; I&#39;ve wanted to go through and make a patch replacing all the<br>
&gt;<br>
&gt; &nbsp; &nbsp; this.propX = null;<br>
&gt;<br>
&gt; with<br>
&gt;<br>
&gt; &nbsp; &nbsp; delete this.propX;<br>
&gt;<br>
&gt; ...but have sort of just never gotten around to it.<br>
&gt;<br>
&gt; as for the proposition here, two thoughts:<br>
&gt;<br>
&gt; 1) overriding the valueOf() thing makes me a little nervous. It seems<br>
&gt; like this is the main reason for you suggesting this in the first place,<br>
&gt; and I can see how this would be handy... but my gut reaction is that<br>
&gt; having to special case our code to deal with a variable that has<br>
&gt; possibly been destroy()ed... it sounds like that&#39;s not a situation we&#39;d<br>
&gt; ever want to be in. the response to that might be &quot;keep on dreamin&#39; uz,<br>
&gt; have you looked at the code lately?&quot; and i&#39;m happy to stomach that<br>
&gt; ;-).... but seriously, in my mind, the destroy() call in my mind should<br>
&gt; only be happenning when the variable in question is absolutely no longer<br>
&gt; needed. which to me means that there should never be code calling it at<br>
&gt; that point. maybe there are some cases i&#39;m not thinking of (event<br>
&gt; callbacks?) but anyways, just a gut feeling. as always, more than happy<br>
&gt; to be convinced otherwise.<br>
<br>
</div>I think I get what you are saying. &nbsp;We&#39;d have to dig around a bit to be<br>
able to characterize the circumstances where destroy has been called<br>
before we expect it to be called. &nbsp;I just know there are places where we<br>
are doing things like checking obj.events because we don&#39;t know if obj<br>
has been destroyed or not yet. &nbsp;My proposal lets us check (obj == false)<br>
instead. &nbsp;</blockquote><div><br>right, right. again, i&#39;m not *totally* against this. it just still seems a little funny<br>
to me. like tweeking with the rules somehow. maybe i&#39;m wack though. let&#39;s <br>
hear what others have to say. <br>
<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Otherwise, it doesn&#39;t improve things.<br>
<div class="Ih2E3d"></div></blockquote><div><br>actually, i think even if it didn&#39;t have that bit, it would still be a helpful improvement.<br>god knows if there is actually any difference in memory, but the simple fact of <br>
replacing 343 million this.foo = null statements with a simple, clean, <br>OpenLayers.Object.destroy(this); I think is in and of itself a really nice improvement.<br>In the cases where we already try to be thorough about setting properties to <br>
null or deleting them, it makes the code simpler, shorter, and cleaner. In the cases<br>where we set to null, i think calling delete on them is more appropriate and more <br>complete. in the cases where we are *not* diligent, then it cleans out stuff that <br>
we forgot to clean ourselves. Overall, this is a big win. I like it a lot. <br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">
<br>
&gt;<br>
&gt; 2) there is the issue here of objects-with-objects. like when you have<br>
&gt; an obj &#39;foo&#39; which has a property &#39;bar&#39;, which is also an object. what<br>
&gt; to do in that case? do we want to make this recursive? base case (obj<br>
&gt; has no properties or typeof obj is simple base type) return, and<br>
&gt; otherwise recursively call OL.Object.destroy() on every (typeof object)<br>
&gt; property? it goes without saying how that can be a dangerous black hole.<br>
&gt; keeping it as is below, however, has the danger of orphaning (?) a bunch<br>
&gt; of memory. is there any way to satisfy both?<br>
<br>
</div>The OpenLayers.Object.destroy function I proposed was not an alternative<br>
to the destroy methods we currently have. &nbsp;Instead it would be called at<br>
the end of the destroy sequence. &nbsp;Things would go like this: I clean up<br>
 &nbsp;everything I am responsible for (possibly by calling<br>
this.foo.destroy()), then I call OpenLayers.Object.destroy(this). &nbsp;This<br>
is intentionally not recursive.</blockquote><div><br>gotcha. yeah, i like that. it&#39;s a good final sweeper. i like it a lot. <br><br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&gt;&gt; anyways, destroy() reform is a fun topic and i&#39;d love to hear what<br><div class="Ih2E3d">
&gt; others have to say.<br>
<br>
</div>Yeah, also interested.<br>
</blockquote><div><br>word. let&#39;s see if anyone else is interested (probably not) :-)<br><br>e<br><br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Tim<br>
<div class="Ih2E3d"><br>
&gt; good suggestion, tim.<br>
&gt; ups,<br>
&gt; e<br>
&gt;<br>
&gt; On Thu, Jan 8, 2009 at 18:56, Tim Schaub &lt;<a href="mailto:tschaub@opengeo.org">tschaub@opengeo.org</a><br>
</div><div><div></div><div class="Wj3C7c">&gt; &lt;mailto:<a href="mailto:tschaub@opengeo.org">tschaub@opengeo.org</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt; &nbsp; &nbsp; Hey-<br>
&gt;<br>
&gt; &nbsp; &nbsp; We don&#39;t currently have a uniform way of determining if an OpenLayers<br>
&gt; &nbsp; &nbsp; object has been &quot;destroyed&quot;. &nbsp;I&#39;m wondering what people think of adding<br>
&gt; &nbsp; &nbsp; something like this:<br>
&gt;<br>
&gt; &nbsp; &nbsp; OpenLayers.Object.destroy = function(obj) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; for(var prop in obj) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete obj[prop];<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; obj.valueOf = function() {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; };<br>
&gt; &nbsp; &nbsp; }<br>
&gt;<br>
&gt; &nbsp; &nbsp; Then we could use the following to decide if something has already been<br>
&gt; &nbsp; &nbsp; destroyed:<br>
&gt;<br>
&gt; &nbsp; &nbsp; obj == false // true after OpenLayers.Object.destroy(obj)<br>
&gt;<br>
&gt; &nbsp; &nbsp; Benefits:<br>
&gt;<br>
&gt; &nbsp; &nbsp; We&#39;d have a uniform way of determining if the destroy method had been<br>
&gt; &nbsp; &nbsp; called.<br>
&gt;<br>
&gt; &nbsp; &nbsp; Drawbacks:<br>
&gt;<br>
&gt; &nbsp; &nbsp; This only works for the level of type coercion done by the equality<br>
&gt; &nbsp; &nbsp; operator. &nbsp;The logical not operator still considers the object truthy<br>
&gt; &nbsp; &nbsp; (so !OpenLayers.Object.destroy(obj) === false). &nbsp;So, we&#39;d probably still<br>
&gt; &nbsp; &nbsp; end up doing things like this (to test undefined or destroyed):<br>
&gt;<br>
&gt; &nbsp; &nbsp; if(obj &amp;&amp; obj != false) {...}<br>
&gt;<br>
&gt; &nbsp; &nbsp; Also, maybe we&#39;re better off checking explicitly for properties as we do<br>
&gt; &nbsp; &nbsp; currently (!obj.events etc.)<br>
&gt;<br>
&gt; &nbsp; &nbsp; Any opinions?<br>
&gt; &nbsp; &nbsp; Tim<br>
&gt;<br>
&gt; &nbsp; &nbsp; --<br>
&gt; &nbsp; &nbsp; Tim Schaub<br>
&gt; &nbsp; &nbsp; OpenGeo - <a href="http://opengeo.org" target="_blank">http://opengeo.org</a><br>
&gt; &nbsp; &nbsp; Expert service straight from the developers.<br>
&gt; &nbsp; &nbsp; _______________________________________________<br>
&gt; &nbsp; &nbsp; Dev mailing list<br>
</div></div>&gt; &nbsp; &nbsp; <a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a> &lt;mailto:<a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a>&gt;<br>
<div class="Ih2E3d">&gt; &nbsp; &nbsp; <a href="http://openlayers.org/mailman/listinfo/dev" target="_blank">http://openlayers.org/mailman/listinfo/dev</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
</div>--<br>
<div><div></div><div class="Wj3C7c">Tim Schaub<br>
OpenGeo - <a href="http://opengeo.org" target="_blank">http://opengeo.org</a><br>
Expert service straight from the developers.<br>
_______________________________________________<br>
Dev mailing list<br>
<a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a><br>
<a href="http://openlayers.org/mailman/listinfo/dev" target="_blank">http://openlayers.org/mailman/listinfo/dev</a><br>
</div></div></blockquote></div><br>