From: Paul B. [ES] <pa...@ei...> - 2008-08-12 15:07:29
|
I did subscribe but I didn't search the entire newsgroup, my apologies. The reason I do not code a loop as suggested is because with heavy loaded list this would be inefficient because the whole loop has to be processed. Paul. On Tue, 2008-08-12 at 08:40 +0200, Eric Bezault wrote: > Paul Bates 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. > > You "discovered" something that is not new: > > http://www.gobosoft.com/eiffel/gobo/structure/traversal.html > > Look at the red comment. Why don't you write your code like this: > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~ > f (a_list: !DS_LINEAR [?ANY]) > local > l_cursor: DS_LINEAR_CURSOR [?ANY] > do > l_cursor := a_list.cursor > from l_cursor.start until l_cursor.after loop > if l_cursor.item = Void then > ... do something interesting here ... > l_cursor.go_after > else > l_cursor.forth > end > end > end > ~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > as suggested in the doc? Note that `go_after' is a routine that > I miss very much in the EiffelBase containers. > > > PS: Please subscribe to the mailing list before posting. > -- ------------------------------------------------------------------------ Eiffel Software 805-685-1006 ext. 107 http://www.eiffel.com Blog: http://www.eiffelroom.com/blog/paulbates Wiki: http://dev.eiffel.com ------------------------------------------------------------------------ |