From: Paul B. <pa...@ei...> - 2008-08-12 16:56:05
|
Weak references is something I have been asking for, for a while now. I remember Manu telling me it would be possible to implement that now with support from existing classes, but it would be far better if there was ECMA specification support. Another way would be to perform automatic, safe clean up via language support: using {f: RAW_FILE} create {RAW_FILE}.make_open_write (fn) f.put ("hello world") end On completion of the code block f.dispose is called, even if there was an exception. That way the file is close during both normal and abnormal operations. Then if the Gobo cursor structures implemented DISPOSABLE to perform the clean up, then it would be simple: using (c: DS_LINEAR_CURSOR [STRING]} list.new_cursor ... end But I digress, this is not the place for language ideas. I should write a wiki page on the idea. Paul. Bernd Schoeller wrote: > Hi Paul, > > it is indeed a "know issue" that GOBO cursors can produce these memory > leaks. The "solution" is to make sure that the cursor is always off after > an iteration. That way it is not referenced by the data structure anymore > and will get garbage collected. > > The proper solution would be to introduce weak references into the Eiffel > language. I am not sure if there is any work on this as part of ECMA. > > Bernd > > On Mon, 11 Aug 2008 20:41:31 +0200, Paul Bates <pa...@ei...> wrote: > >> We've detected a memory leak when using gobo data structure cursors that >> do not run to the end, and currently there is no way to clean them up >> nicely. >> >> Take the following code >> >> f (a_list: !DS_LINEAR [?ANY]) >> local >> l_cursor: DS_LINEAR_CURSOR [?ANY] >> l_stop: BOOLEAN >> do >> l_cursor := a_list.cursor >> from l_cursor.start until l_cursor.after or l_stop loop >> l_stop := l_cursor.item = Void >> if not l_stop then >> l_cursor.forth >> end >> end >> end >> >> Passing a linear structure to 'f' where any item is Void will cause the >> leak because the list never goes 'off'. We cannot call >> DS_TRAVERSABLE.remove_traversing_cursor and it is not a good idea to do >> so because it may have not been added the the managed list or cursors, >> given the current lazy-eval implementation. >> >> The current solution is to run out the cursor in another loop or run out >> the cursor in the original loop but conditionally process the loop's >> functional body. Neither of which look that nice. >> >> Best, >> Paul. >> >> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> gobo-eiffel-develop mailing list >> gob...@li... >> https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop > > > |