• 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

I think I have a memory leak: 33 megs of char arrays.. what to do?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marvin,

Welcome to JavaRanch!

Remember that Strings and StringBuffers contain char[]'s internally, and it's likely those char[]s 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?
 
Marvin Diggler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Yes, I have TreeMaps filled with Strings. I have a lot(probably thousands) of TreeMaps actually because I have to show parent to child relationships and the number of hits for that relationship.

I am just baffled, because why if I save the data, and then reload it, the program is only using 31 megs as compared to the 71 it uses when it originally scans the files.

If its a problem with my maps, wouldnt the program take 71 megs when I load the data (from a serialized object)?
 
Marvin Diggler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also, I do use a string tokenizer for the log file. It just does one line at a time and then I reinit the string tokenizer for the next line.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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[].
 
Marvin Diggler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anything I can do in my program to make sure the correct size char[] is used?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on how you parse the logs. What are you doing now?
 
Marvin Diggler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
This tiny ad is wafer thin:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic