Jump to content
  • Advertisement
Sign in to follow this  
Kevinator

[java] Memory Problems

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, my problem is that I'm running out of heap space when I'm only about 20% complete with my problem, so increasing the space allocated to the JVM isn't exactly a valid solution. Here's what I'm basically doing:
String aHugeString="";
Foo[] foo=new Foo[12000];
for(int i=0; i<12000; i++)
{
  aHugeString=getHugeString(); //string is roughly 32kb
  foo=new Foo(aHugeString.substring(1323,1335)); //each element of foo contains roughly 30 bytes
}





It can't be the array, can it? It seems to me that there should be plenty of heap space for the array. What I'm thinking is that the string isn't getting garbage collected or something.. I don't know why it wouldn't, though.. So please, if there is something obviously stupid I'm doing please set me straight. This really shouldn't be happening.. Progress update: I tested out a mockup array without all the other string processing and it does just fine. I'm currently testing a version with periodic manual garbage collection and we'll see how it goes. update 2: the manual gc doesn't make a difference.. I'm stuck. update 3: I've been scouring the internets for a solution, and came across THIS.
Quote:
As such, substring() calls are incredibly fast: you're just allocating a new object and copying a pointer and two int values into it. On the other hand, it means that if you use substring() to extract a small chunk from a large string and then throw the large string away, the full data of that large string will continue to hang around in memory until all its substrings have been garbage-collected. Which could mean you carrying around the complete works of Shakespeare in memory, even though all you wanted to hang on to was "What a piece of work is man!"
O_o Wow. That... that sucks. Trying to find a workaround, as I think this is what is plaguing my app. [Edited by - Kevinator on August 14, 2008 12:07:35 AM]

Share this post


Link to post
Share on other sites
Advertisement
Transfer the information with an array of char.


String aHugeString="";
Foo[] foo=new Foo[12000];
char temp[] = new char[12];
for(int i=0; i<12000; i++)
{
aHugeString=getHugeString(); //string is roughly 32kb
aHugeString.getChars(1323,1335, temp, 0);
foo=new Foo(String.copyValueOf(temp)); //each element of foo contains roughly 30 bytes
}



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!