Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Do JProfiler works correct??  RSS feed

 
jiya kaur
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cuentlly in my project, when i open a parent screen, and then a child screen o it. I see lots of objects created.Now i exit the Child screen,do onec GC from JProfiler but the objects are not gone, now i exit the parent screen and do GC,this time child class objects are gone,but parent class objects are still there.Now if i open some other parent class that is not depent on this parent class ,and if i exit the second parent class.now all the object of first parent class are gone, but second parent class that i closed are not gone.My Team lead told JProfiler is not wrong.Need some help.
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The garbage collector will collect only objects that are no longer being referenced. Just because you close a window (the child screen) does not necessarily mean that the objects being used by that window are no longer referenced. If I would have to venture a guess from your description of the situation (not knowing what your code looks like), I would say that the parent window is maintaining a reference to the child window.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GC does not always free all unreachable objects.

Also objects which are finalizable may need two runs of GC. First to determine that finalize() has to run and another after finalize() completes.

Due to this, I sometimes use this code
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope that code is not in a web application. Calling System.gc() is not recommended within code deployed to an application server, especially since it causes a full collection.

If you have finalizers, the first GC will cause all such unreferenced objects to be placed in a queue where the finalizer thread will run through their finalizers one at a time, marking each as garbage-collectable after each finalizer is done. If the third GC call you are making happens before that thread is done doing its thing, some of the objects still might not have been cleaned up.

Besides, I do not think that JProfiler would show objects in the finalizer queue as still being active. Yes, they are still taking up space in the heap, by they are unreferencable.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!