[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reasons, why Miss Scheme should collect her garbage beforeshutdown.
...
> garbage collection is used for managing memory, not for managing
> other resources
... because: ...
> even when your object is finalised you can't guarantee when that
> will happen.
This finally makes me understand and is so logical ... blindness must
have struck me before!
Besides, what triggers garbage-collection?
> Better is to provide an explicit means of freeing/closing resources.
> A common idiom in Common Lisp and Dylan is to do a 'with...' style
> macro:
>
> with-open-file(fs = "blah.txt")
> do-something(fs);
> end;
>
> The macro frees or closes the resources at the end of the scope.
I see: I should use a defmacro or a syntax-case-macro to transform
something like this:
(with-external-objects ((obj (make-external-object args)))
(operate-on-external-object obj)
...)
... into this:
(let ((obj (make-external-object args)))
(operate-on-external-object obj)
...
(clear-external-object obj))
... or this:
(let ((obj (make-external-object args)))
(dynamic-wind
(lambda () #f)
(lambda ()
(operate-on-external-object obj)
...)
(lambda () (clear-external-object obj))))
The second variant should clear the external object if a continuation
is used to jump out of the scope of the 'with-...'-form. Though I'm
not quite sure if this is absolutely 'continuation-proof', the
external object will at least never remain un-freed.
I will redo my program in this fashion and then it shall be simpler
and more robust.
Sebastian