Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Unreferenced object not garbage collected  (Read 1178 times)
0 Members and 1 Guest are viewing this topic.
Offline digitprop

Junior Member





« Posted 2005-03-09 19:48:41 »

I am currently hunting down a memory leak in Kelvin Kazoom (http://www.digitprop.com/kazoom/index.html), and have come across a strange phenomenon:

I have app. 20 objects in a Hashtable. I clear() the hash table and am pretty sure that there are no other references to these objects (from looking at the code, and from the very useful Reference Scanner - http://jb2works.com/refscan/usage.html).

If I now create WeakReferences on all these objects before clear()'ing the map, then run the garbage collector (via System.gc()), all the WeakReferences show null references (i.e. the objects have been gc'ed) except for the object last returned by the Hashtable's keys() enumeration.

Has anybody come across something similar? I know that System.gc() is not guaranteed to do anything, but find it very strange that everything is gc'ed except for one object.

When I wait a few seconds, then have a second look, the one remaining object is also eventually gc'ed.

One more detail: Reference Scanner correctly shows the uncollected object, but no references to it. So it seems like the object is not in the GC queue for some reason, but has no references whatsoever.

M. Fischer . www.digitprop.com
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #1 - Posted 2005-03-09 20:46:10 »

You're obviously going to need to show us some code.
Garbage collection occurs only on the objects that are not being used.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Vorax

Senior Member


Projects: 1


System shutting down in 5..4..3...


« Reply #2 - Posted 2005-03-09 21:57:56 »

Quote

I have app. 20 objects in a Hashtable. I clear() the hash table and am pretty sure that there are no other references to these objects (from looking at the code, and from the very useful Reference Scanner - http://jb2works.com/refscan/usage.html).


A couple of possiblities I can think of:

1) Since Reference Scanner operates as a dameon thread in your app, perhaps it is actually referencing the remaining entry in some way?

2) You may be witnessing an optimization of some kind.

Either way, it's only one object, then it gets GC'd.  Is it really a big deal or is the investigation purley academic?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline digitprop

Junior Member





« Reply #3 - Posted 2005-03-10 06:16:58 »

Thanks for the answers!

KILER: I know that code would be helpful, but it's much too much code; I have already tried to reproduce it in a small test class, but that doesn't work. Obviously the problem 'needs' the complex memory allocation of the application.

I know that the obvious explanation would be a reference I missed. Therefore I tried to look as diligently as possible before posting this.

Vorax: You are probably right in that this is some kind of optimization. And no, it's no big deal and more of an academic question. Also, I thought this may be interesting for others - I have wasted quite some time tracking down a missed reference, because I assumed that after System.gc() every non-referenced object would be cleared.

I know that the method is not meant to guarantee this, but this is what I have seen so far when I investigated memory problems.

M. Fischer . www.digitprop.com
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2


Make it work; make it better.


« Reply #4 - Posted 2005-03-10 10:13:03 »

The gc is a generational one.  So it only collects objects that are a certain age.  Since the one not being collected had the last reference to it released, it is probably just not flagged for gc yet.

Offline digitprop

Junior Member





« Reply #5 - Posted 2005-03-11 15:33:13 »

Quote
The gc is a generational one.  So it only collects objects that are a certain age.  Since the one not being collected had the last reference to it released, it is probably just not flagged for gc yet.


Ah, that makes sense. I guess things aren't quite as simple as I thought them to be...

M. Fischer . www.digitprop.com
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (23 views)
2014-04-15 18:08:23

BurntPizza (18 views)
2014-04-15 03:46:01

UprightPath (32 views)
2014-04-14 17:39:50

UprightPath (16 views)
2014-04-14 17:35:47

Porlus (32 views)
2014-04-14 15:48:38

tom_mai78101 (58 views)
2014-04-10 04:04:31

BurntPizza (116 views)
2014-04-08 23:06:04

tom_mai78101 (216 views)
2014-04-05 13:34:39

trollwarrior1 (183 views)
2014-04-04 12:06:45

CJLetsGame (190 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!