This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hi, Ran JProfiler no my program to see why I keep getting an OutofMemory error. It appears that I have a lot of char's.. according to the program it gets up to 33 megs and just keeps going until I recieve the error.
I'm confused though, because I can see anywhere I use a char. In a couple place, I used charAt() and substring(), but those variables are reused so the reference should be destroyed with time the varible is reassigned.
If I run my program with 3 log files (its a web log scanner), it gets up to 71 megs. However, if I just load my program and have it load the data (just a serialized object), the program only takes about 30 megs of ram. I am assuming the memory leak is not happening with the object that stores the data, it must be somewhere else in the program. Is this a good assumption?
Remember that Strings and StringBuffers contain char's internally, and it's likely those chars that are giving you trouble. Do you have a List or Map full of Strings or StringBuffers? Or are you using StringTokenizer, which will keep such a collection internally? Are you keeping more data that you need? Or perhaps you're simply loading all of a log file into one humungous String and then parsing it?
Depending on how a String is constructed, it might contain a larger char than is needed. Perhaps when the data is loaded in via serialization, the Strings are built to use exactly the correct size of char.
Joined: Aug 30, 2005
Is there anything I can do in my program to make sure the correct size char is used?
author and iconoclast
Depends on how you parse the logs. What are you doing now?
Joined: Aug 30, 2005
Currently, each line of the log is read with the StringTokenizer. I then call substring on the URLs (page and it referrer) to remove http://. Then the the URLs are stored in a HashMap. Do I need to call some type of resize method along the way?