clojurescript goog libs - dispose - and garbage collection

2012-01-16 Thread Dave Sann
If you use something like goog.async.Delay, or other goog closure libs that 
produce objects that have a dispose method, 

Is it imperative that .dispose is called when you are done with this object?
What happens if not? memory leak?
How do you manage this if you are passing such objects around in function 
closures or other structures 
where you may not (want to) know exactly when this may be no longer 
required?



I was looking at this thread - and the conversion of js/setTimeout to 
goog.async.Delay, along with the enfocus implementation

https://groups.google.com/d/msg/clojure/epHVbmcNzgs/3pVyS_AKCYUJ

from enfocus:

(defn setTimeout [func ttime]
  (. (new goog.async.Delay func ttime) (start))) 


what about functions such as this?

(defn repeat-with-timeout 
  [f t]
  (let [stop (f)]
(if-not (= true stop)
  (js/setTimeout #(repeat-with-timeout f t) t 

Cheers

Dave




-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: clojurescript goog libs - dispose - and garbage collection

2012-01-16 Thread ckirkendall
Dave,
I think you are right that my implementation does cause a memory leak
over time.  It interesting that I can't find a single example of
someone calling dispose on an object like this.  The google code for
disposable hold a global reference to all disposable instances and
only removes when dispose it called.  It might be better to use the
static function goog.Timer.callOnce(listener, opt_delay,
opt_handler).


Creighton Kirkendall

On Jan 16, 6:25 pm, Dave Sann  wrote:
> If you use something like goog.async.Delay, or other goog closure libs that
> produce objects that have a dispose method,
>
> Is it imperative that .dispose is called when you are done with this object?
> What happens if not? memory leak?
> How do you manage this if you are passing such objects around in function
> closures or other structures
> where you may not (want to) know exactly when this may be no longer
> required?
>
> I was looking at this thread - and the conversion of js/setTimeout to
> goog.async.Delay, along with the enfocus implementation
>
> https://groups.google.com/d/msg/clojure/epHVbmcNzgs/3pVyS_AKCYUJ
>
> from enfocus:
>
> (defn setTimeout [func ttime]
>   (. (new goog.async.Delay func ttime) (start)))
>
> what about functions such as this?
>
> (defn repeat-with-timeout
>   [f t]
>   (let [stop (f)]
>     (if-not (= true stop)
>       (js/setTimeout #(repeat-with-timeout f t) t
>
> Cheers
>
> Dave

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojurescript goog libs - dispose - and garbage collection

2012-01-16 Thread Cedric Greevey
On Mon, Jan 16, 2012 at 9:45 PM, ckirkendall  wrote:
> Dave,
> I think you are right that my implementation does cause a memory leak
> over time.  It interesting that I can't find a single example of
> someone calling dispose on an object like this.

Perhaps there should be a with-disposables macro in ClojureScript for
things that should be disposed, in much the way there's with-open in
vanilla Clojure for things that should be closed.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojurescript goog libs - dispose - and garbage collection

2012-01-16 Thread ckirkendall
Dave,
I found a good explanation of disposables:
http://groups.google.com/group/closure-library-discuss/browse_thread/thread/b2b38d0045464439

Creighton Kirkendall

On Jan 16, 6:25 pm, Dave Sann  wrote:
> If you use something like goog.async.Delay, or other goog closure libs that
> produce objects that have a dispose method,
>
> Is it imperative that .dispose is called when you are done with this object?
> What happens if not? memory leak?
> How do you manage this if you are passing such objects around in function
> closures or other structures
> where you may not (want to) know exactly when this may be no longer
> required?
>
> I was looking at this thread - and the conversion of js/setTimeout to
> goog.async.Delay, along with the enfocus implementation
>
> https://groups.google.com/d/msg/clojure/epHVbmcNzgs/3pVyS_AKCYUJ
>
> from enfocus:
>
> (defn setTimeout [func ttime]
>   (. (new goog.async.Delay func ttime) (start)))
>
> what about functions such as this?
>
> (defn repeat-with-timeout
>   [f t]
>   (let [stop (f)]
>     (if-not (= true stop)
>       (js/setTimeout #(repeat-with-timeout f t) t
>
> Cheers
>
> Dave

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojurescript goog libs - dispose - and garbage collection

2012-01-19 Thread Dave Sann
Thanks for the pointers.

Cedric's idea is interesting.

I have to say, I don't the idea of disposables in general - its back to 
manual memory management.
I suspect they came up, out of necessity, because of how IE (used to?) fail 
to garbage collect between DOM and JS.

Cheers

D

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en