GWT Garbage Collection

I am creating a new presenter, for example:

new MyPresenter(new MyView()); 

It registers some event handlers and binds them to a view and the like. In the end, I could β€œclose” this view so that the browser would no longer be displayed by the browser. I do not maintain a link to this instance of MyPresenter anywhere.

In the Google forums in this section, the usual answer is β€œset links to zero,” then don't worry about it. Unlike Javascript, I can just say this = null; in Java for obvious reasons. But in Javascript, it is very easy to exclude references to objects that, as I know, will no longer be used.

My question is: how can I find out if this host was garbage collected because I do not support the link to it? It very clearly exists. Do I have to believe that GWT and JS will take care of this? Or do I need to save my own link to MyPresenter so that I can manually null it when I am done with it?

+6
source share
1 answer

There are two types of memory leaks:

  • DOM / Browser Memory Leak
  • Application memory leaks.

DOM / browser level memory leaks usually persist after the application closes. AFAIK only affects older browsers (IE6), and the reason GWT uses a special way to attach handlers.
This should be a problem not related to modern browsers, at least they will be no problem if you close the application. However, they can become application memory leaks. (See here for more details). But overall, modern Javascript GC is pretty good at freeing up unused memory.

Application memory leaks can be a problem when working with running applications, as well as when dynamically creating multiple views / presenters and storing links through Eventhandlers. But here it really depends on the volume of parties involved.
This post is a good link with more details on this.

Finally, to make sure that you really do not have application memory leaks, you should use the Dev Tools Heap Profiler to check memory consumption for a longer period.
This blog post contains more information about this.

+2
source

Source: https://habr.com/ru/post/913952/


All Articles