-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leaking b/c of handlers #1
Comments
On 10/03/2012 06:16 PM, Brandon Donnelson wrote:
I am aware of this article. lib-gwt-svg used to follow the pattern My understanding is that leaks were created in early browser Can you provide more details on your claim ? Is it based on just reading Lukas |
I haven't tried OMNode.cleanup() yet. Thanks for the info. I've been profiling the svg rendering over and over I see the heap stack growing in the apps I've tried and SVG elements although getting cleared are lingering around in the heap profiling which is alluding to memory leaking. The other thing I see is the attaching the handlers directly to the dom and not to the gwt widget handler manager. I'm curious why you chose to use to register the handlers to the dom and not extend widget or use the widget mechanisms? If you look into that Widget class you'll notice mechanisms to deal with tear down of the element(s) and handlers, which I imagine you're already aware of. I'm seeing signs of leaking all though I can't say its conclusively yet, although when looking at the profiling I'm seeing a long detached list grow. I guess my expectation is that the widgets that get cleared to get garbage collected. Although maybe its a matter of hows its written either higher or lower... I like to use GWT as it manages the attaching, detaching and such and makes this convient. But when working with an underlying jsni library, its nice to build this into the widget, so the widget manages the references. |
Hi gents, My own first guess is that a handler is being registered on something long-lived like the document, or the static OMNode.eventBus, and simply not unregistered. The garbage collector fault mentioned in that article is probably a red herring, at least in this context. It seems doubtful that a browser capable of rendering SVG would have a garbage collector that broken. Are other DOM elements freed from the heap on each collection cycle? Is it only the detached SVGs that linger around? Do they eventually cause a memory fault? What happens if OMNode.eventBus is forcefully cleared after each SVG is thrown away? |
From what I can tell so far the registering of the events are creating a references to the object groups and the OMNnode.cleanup() has to be explicitly called which I expect it to break the objects reference, but I'm not sure this cleanup is doing its job yet b/c I still have so many lingering SVG elements in the detached heap profile and event handlers. Then again there are many children in my svg, I have to consider all the possibilities of cleanup. I did find some context alluding to object group cleanup in chrome documentation, although you have to break all the references to the wrapper before it will get freed. I don't see this happening with event registering at the moment. |
I'm pretty sure cleanup isn't going to work. I see all this hooking up to the dom stuff and no removing going on. I'm not sure why a static eventbus is doing, but what happens to an handler gets added to that. I'm not sure this is going to get cleaned up? And what about DOMHelper.bindEventListener((Element)ot.cast(), type.getName());? This is hooking up all kinds of events to the DOM. I compared this to RichTextAreaImpl(Standard...) and such, and its similar, except one thing, your missing all the unhooking. The way I see it and correct me if I'm wrong, but the only way to clean up the memory leaks is unhook the element wrapper completely. That is remove the handlers and anything that may get atatched to the window for the element. I can't see this falling under the cyclic cleaner your talking about. I'd copy the RichTextAreaImpl approach to hooking and unhooking the listeners wanted. Or CanvasElement. Thing is your not using the widget class, so it'd be tough to know when something gets detatched in the composite scope, so I'd use widget too. I have to say I'm impressed with whats put together! Good job. |
This is what I'm looking at: http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java#308 - How RTA hooks up... https://github.com/laaglu/lib-gwt-svg/blob/master/src/main/java/org/vectomatic/dom/svg/impl/DOMHelperImpl.java#L46 - How yours is hooking up. I see remove type methods, but they don't have it all and/or they don't percolate up to the OMNode... |
Hi Brandon, First thanks a lot for spending time on this problem. I have read your lib-gwt-svg design is fairly simple. One needs to distiguish between three
How are these objects hooked ? There are 4 kinds of relationships to 1/ Overlay types / Wrapper types ; Overlay types and Wrapper types always 2/ Events ; The event bus is a kind of dictionary which maintains pairs of 3/ Overlay types hierarchy. This is basically the DOM hierarchy. Note that 4/ Widget / Wrapper types. The SVGImage has a reference to the root For each of these relationships, you have a dedicated cleanup method:
Of course memory leaks are possible. For instance, if you have a handler Lukas On Fri, Oct 5, 2012 at 9:14 PM, Brandon Donnelson
|
I can see what your saying but I have to admit I like leaning on the widget to do the work. This is probably why I'm not digging with working with elements. :) When I use cleanup in our main project I don't see it working of course this tells me I'm missing something. But using elements instead of widgets I suppose is my crux because I enjoy the fact the widget takes care of many of the needed duties to prevent leaks. I'm not sure it would impact the svg elements and that said it seems that your doing most of the same functions as the widget anyway. I have a feeling it might simplify some of your logic if you used the widget instead of the sinking methods for events. I'd really like to say .clear() and let the widget deal with all the children... I've also begun testing to see if you auto GC reference is working. So far when drawing one svg element over and over I see the heap profile increase over time wether I use cleanup or not. I've got to make sure all my ducks are in a row and I want to do more testing but I'm not convinced leaving the GC up to the browser is the best option and for me, I'd prefer to programmatically clean up. I think I'm going to test getting rid of the OMNNode and extend widget, this seems like an easier proposition to fix our project. :) |
So far my preliminary results of removing the document as a wrapper and extending the OMNode as a widget got rid of my memory leaks and I think its far easier to add and remove regarding the gwt widget framework. :) |
It appears using this library is creating memory leaks b/c the handlers don't have a back reference.
I'd suggest integrating the widget framework into your elements so the handlers references can be destroyed.
https://developers.google.com/web-toolkit/articles/dom_events_memory_leaks_and_you
The text was updated successfully, but these errors were encountered: