Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory Leak?

Status
Not open for further replies.

scheenstra

Programmer
Feb 28, 2002
15
0
0
US
Hi, i'm having problems with some java apps. i'm running several apps off a CD that runs through a table of contents page. After running a few of them, they start to break and freeze up. I ran them while watching the task manager and it appears to be a memory leak. when I start the T.O.C. I have about 122 megs available on a machine with 256 total. through running the apps I drop down to mid 80's. I don't get the memory back, until I exit the table of contents page. even though I have left the page that the app is running on. Is their anything besides a memory leak that could cause this? Any help is greatly appreciated.Thanks.
 
Memory leaks (in theory) don't occur in java as they may in c/c++ because of java's inbuilt garbage collection - which in effect destroy's objects once they are no longer required.

I dont't quite get what you mean by running applications through a table of contents - but it sounds like once you fire this 'T.O.C' up, and run the applications, then memory is not being freed until the entire TOC is exited -- the applications may still be running in the background or not completely destroyed until this TOC application itself is exited.

This could be because some systems, when reading data from a drive, buffer the data in RAM, before processing/outputting it. This may be what is happening to your PC - in effect stopping the appliocations running does not free the RAM because the CD is still being read....I don't know - its possible !!!!!

Try copying everything from CD to hard drive, and repeat process.
 
Hi scheenstra,
my guess is that the TOC runs in a browser window (maybe IE) and as long as this browser exists, the Java Virtual Machine will exist in memory, too (once called). So, if you close all the programs, but not the TOC, the the JVM will still need some space

Christoph
 
Sorry i wasn't more clear. The table of contents does run off IE, just like a web page, where you choose the drive letter the the CD is running in. Then you can click on whatever chapter you want to run(which also run in IE). So if i understand what i'm hearing, this might not be a code problem, but rather the way it has been setup to run. would this be correct. Also, can't their still be memory leaks in java if you leave a pointer to an object that is no longer being used, with the pointer still in place, the garbage collector won't throw it out. right? thanks for all the help -- scheenstra
 
Don't make the mistake of assuming that their can't be memory leaks in Java Applications. Memory leaks in Java are just much more subtle. The garbage collector only reclaims memory from objects that are no longer actively referenced. Memory leaks in Java result from a central point never releasing references to objects that it no longer needs. If the reference is never released then it is never available for GC.

Don't even get me started on the types of memory leaks that I have seen in applications using JNI. Point is, too many people get that warm and fuzzy feeling thinking that they can do no wrong when programming in Java. It is just a false sense of security.
 
wushutwist beat me to the punch. There certainly are memory leaks in java and many poorly written apps have them.

For example, if I have a homegrown List that I've created that implements clear() in the following fashion, Houston we have a problem:

public void clear()
{
this.size = 0;
}

You see, internally, the list now thinks that it has no contents but I may actually have thousands of live objects that have strong references that will never be GC'd. In order to prevent this, I would either need to throw away the array that held them and create a new one representing my new List (in which case the array and all it's contents would be gc'd) or I would need to explicitly null every object in the List.

These are the kinds of insidious bugs that catch novice programmers (like the ones always asking us on the forum to do their homework) and even some experienced ones.
 
The plot thickens, i've been playing around with this thing, and i've noticed that if i have an IE window open, before i open the IE table of contents, then i don't get my lost memory back until i close the original IE window, even if its just sitting on some web page. does anyone know how IE handles memory, it seems like the first IE window opened is the head master of them all. would this be accurate? as always, thanks for all the great advice/help. --scheenstra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top