Memory leaks
Hi.
In my application I'm starting up 7 threads, each one supposed to read a lots of data from an ascii file, write to a database and write back the result to another file.
Somewhere in the application framework I have a memory leak.
I believe the cause is one of three:
1. Reading from file using BufferedReader
2. Writing to file using a OutputStreamWriter
3. Database access.
Though I'm very careful flushing and closing streams and closing database connections, the problem remains.
Sorry I cannot show you the whole code, but I hope someone has an ide just reading this little piece of information.
btw, using Jdk1.2.2 and JDBC2.0
best regards
Andreas
[738 byte] By [
Siggeman] at [2007-9-26 2:44:30]

Sorry I cannot provide more information.
The threads are running in a neverending loop, so I don't believe the threads themselfs are the problem.
The memory leak I spotted just watching the taskmanager. It should be enough?
I have created Wrapperclasses around my File class, BufferedReader and OutputStreamWriter. In thoose I override the finalize methods, and these methods are executed. When accessing the finalize method, could I then be absolutely sure that the object is ready for the gc?
regards
Andreas
Hi!
I think you could wasting a lot of time, if you trying to figure it out manually. Try using an application (Memory profiler) that measure what part of program that uses up most memory. There is a lot of them out there (on the internet).
I think that are a free version of such tool from Hewlett Packard. Since my harddrive crash I do no longer have the link to this tool.
Regards
Johan
joka at 2007-6-29 10:24:51 >

If the finalize method is being called then the next time the garbage collector it should release any resources being used by the objects.
You say that there is a memory leak, does it keep on growing or does it stop once the amount of memory being used by the process gets to a certain size ?
Have you experienced any Error:outofmemory errors when running your application?
If this isnt the case and you're guessing that memory is being lost via the taskmanager then you'll probably wasting time. Database access tends to extend memory allocation of the jre, it can inflate the memory used but providing your doing all the right things such as closing the sockets/files/connections then your memory should be reusable by the jre.
If this is really bothering you, then write customised finalize methods for each of your classes so that you can track the number of objects created and the number destroyed. ALthough this wont reclaim 'leaked' memory its sometimes helpful to figure out which parts of your application are being routinely gc'ed.
rbyrom at 2007-6-29 10:24:51 >

Before you say you have a memory leak, understand that memory is not garbage collected until it is no longer referenced. If you have a loop that is addind itmes to a vector or something, the memory is going to increase without bound. This is not a memory leak. Theoretically, Java doesn't allow memory leaks. A memory leak occurs when a program discards all references to an instantiated object. This is when Java is supposed to return memory to the OS. If you are really experiencing a memory leak then there is something wrong with the JVM, but I doubt that is what is really happening. It sounds like one or more of your threads is using memory like it is going out of style.
dubwai at 2007-6-29 10:24:51 >
