• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory Leak

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread instances were not garbage collected even after the thread came out of the run() method, why?
How to make it unreferenced. I tried by invoking join method and then setting it to null, but the result was failure.
Please suggest a solution?
[ October 15, 2003: Message edited by: m muruges ]
[ October 29, 2003: Message edited by: m muruges ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hiii...
there is no way to force GC.. you can only call that method.. when it wi;; run and garbage collect is totally up to system... it can happen anytime... it is the lowest priority thread... and will run only when no other higher priority tasks is remaining...
Thanks
Amit
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please dont make update like this. I didn't ask how to run GC. I am profiling my code thru' profiler and found memory leak in Thread objects. I have to fix.
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any updates please?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you keeping a reference to the object that extends Thread or implements Runnable anywhere? That would prevent it from being garbage collected.
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am doing is - I am having a vector which contains the list of active threads. I am checking the active state of all threads periodically. If any of the threads finishes its work, I am removing it from the vector and assigning it to null. Even then it is not getting GCed.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your worker thread class, are you using any resources like files, sockets or database connections? In your run() method, after you do whatever work you have to do, are you explicity closing all these resources?
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am doing is - I am having a vector which contains the list of active threads. I am checking the active state of all threads periodically. If any of the threads finishes its work, I am removing it from the vector and assigning it to null. Even then it is not getting GCed.
I don't like your choice of a container (Vector is a legacy collection and should not be used), but that's another matter. If your expectation was that the thread was eligble for garbage collection after it was finished, your expectation was wrong: since the thread was still in the Vector, it was reachable and therefore could not be GCed. This is a common source of memory leaks. But since you are saying it is not GCed even after you remove it from the Vector, my guess is that perhaps you store it in some [i]other[/b] collection or refer to it from some other place.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eugene Kononov:

I don't like your choice of a container (Vector is a legacy collection and should not be used)


Where does it say that in the API documentation? Vector isn't depreciated.
Compare it to java.util.Date, which has been gutted in the newer API's.
I don't see anyone clamoring to depreciate the Vector constructor of
JList or JTable or JTree . Take a look at their respective data models. Vectors.
I know you are aware of this post comparing the performance of ArrayList and Vector and coming up with some surprizing results, but how about this article which delves even deeper into the collection controversy.
It's not as easy as "never use Vector". As with all engineering problems, it is the right tool for the task at hand. And sometimes, that tool is Vector.
How's that for a threadjack!
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does it say that in the API documentation? Vector isn't depreciated.
I never said that Vector is deprecated, just that it is a legacy collection, which is not the same thing. With legacy collections (such as Hashtable and Vector), it is as simple as this: there is never a good reason to use them with new code, so don't use them.
If you question the term "legacy", -- it's all over Sun's Collections Tutorial. This issue has been discussed at JR on many occasions. Here is an explanation by Peter den Haan about why Hashtables, Vectors, and Enumerations should not be used.
[ October 30, 2003: Message edited by: Eugene Kononov ]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see this quote in the first link you cite:
"there are times when you still need to use some of the original collections capabilities."
Nowhere do I see the word "legacy" or any statement approaching the finality of this one:

Originally posted by Eugene Kononov:
there is never a good reason to use them, so don't use them.


Peter den Haan has one good point, that is that the Collections framework is better thought out than the kluge that is Vector+Hashmap+Collections. His performance concerns have been demonstrated to be, if not false, than of little concern in a non-trivial application. And as for code consistency and other developers, well, managing developers is like hearding cats. . .
That one reason of Peter's is still not enough to write off Vector forever. You have the API classes above for a counter example. Want to throw a variable number of data (so as to preclude using an array) at a JList? Use a Vector or implement your own model using ArrayList. The performance differences are splitting hairs so it boils down to: do you want one more class to write, debug and maintain? My answer would be no, the API provides a perfectly good class so use it.
Personally, I use ArrayList to the exclusion of Vector. I just don't like the word "never". Things are never that easy.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nowhere do I see the word "legacy"
From javadocs of java.util package:
"Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array)."
I just don't like the word "never". Things are never that easy.
Umm, is that what they call "irony"?
Look, Vectors are bad, they are a mistake from Java 1.1 that haunts the developers to this day. They are the nighmare that leads to code that is hard to evolve. They are anathema, a curse to OOP. If you use vectors, you may be stuck with them for a long time, while with "real" collections (as opposed to the retrofitted collections), there is a nice separation of interfaces and implementations that can be easily swapped. If you want to use a synchronized List, there is always a Collections.synchronizedList() method. There is no reason to use Vectors in new code, it's as simple as that.
[ October 30, 2003: Message edited by: Eugene Kononov ]
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your suggestions.
I released all the resources before the thread returns from the run method. Even then it didn't get GCed. The same problem happens with the JDBC driver(miniSql-JDBC driver) that I am using in my application. There the resultset object (which implements Runnable) not get GCed even after I close the resultset object and the statement object associated with it.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may be your problem: The mSQL-JDBC driver is unsupported:


I have long since switched to using MySQL for personal uses and thus no longer keep the mSQL-JDBC package up to date. I have no idea how well it works with the current JDK or the current release of mSQL.


http://www.dasein.org/soul.jsp
He goes on to say that he updated the driver through mSQL 1.x. mSQL is now in the 3.x range. I suggest you look for a newsgroup or other forum that deals specifically with the mSQL-JDBC driver and search it for GC issues. Maybe re-post a more specific question in the JDBC forum here about mSQL and GC in particular.
[ October 31, 2003: Message edited by: Joe Ess ]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eugene Kononov:

I just don't like the word "never". Things are never that easy.
Umm, is that what they call "irony"?


Good catch! Serves me right for trying to make sense at the end of the work day.


They are anathema, a curse to OOP.


Obviously this has become a religious argument, akin to Emacs vs. VI or Mac vs. PC vs. Linux. I've said my peace and I will leave it at that.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may not have anything to do with the original problem, but I once had a "memory leak" that was traced to Threads getting created but never start()ed. They hung around due to a reference in the ThreadGroup and were never cleaned up.
Bill
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I want the solution for the original problem, leave the mSql driver problem.
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following program leaks memory if I run it in java1.1.6 but, it is working fine in java 1.4.
any workaround for this problem since my appln. is running in java1.1.6?
Leak is MyThread object
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by m muruges:
The following program leaks memory if I run it in java1.1.6 but, it is working fine in java 1.4.
any workaround for this problem since my appln. is running in java1.1.6?


Makes a strong case for upgrading your VM. What's preventing you from doing that since you'd solve your problem AND get better performance from 1.4
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The product is running in solaris 6. It is in maintenance mode. If I change the jre to 1.4 I dont know how it is compatible with solaris 6. And the regression will be more in my application.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the regression will be more in my application.
Makes a strong case for automated testing. What prevents you from using JUnit?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic