We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a problem... I have to create an array that is pretty large,but used only rarely so I decided to save it to a file since it is predefined (but changes every startup so I have to check every startup again). but for some reason it still uses an extrem amount of memory eventhough I created a local array in setup. So how do I "remove" the array properly ?
void setup(){
String[] hi = new String[10];
for (int jf = 0; jf < hi.length; jf++){
hi[jf] = 5 + 5 - jf;
// something that needs really much memory and is difficult to calculate (instead of that)
}
saveStrings("test.txt",hi);
}
void draw(){
if (key == 'g'){
String[] temp = loadStrings("test.txt");
printArray(temp);
}
}
so how do I properly unload the String ,because when I test my other program it uses memory up to 750k and it keeps staying that high, but when I remove the large array from the program's code it works fine using 30k memory.
Thanks in advance :D
Answers
edit post, highlight code and press ctrl-o to format.
leave a blank line before and after.
CHECK WHAT YOU'VE POSTED.
for some reason (i dont know why) it wont format easier to read sorry for that
@sLucas --
If you paste this code into PDE and press "Run", it
What line is highlighted? What is the error? Why might it say that? Is there something that you should normally do that you have not done here?
excuse me
this should work now but i need some help on the question i mentioned at the beginning
Maybe you guys dont get my point, because my english isnt that great since i m not native, so I'll try and explain it again
the posted code is just simplified to show you an example of my problem the real code is complex but I made some search for problem research and can say that it will be solved if someone could tell me a way for removing the current array out of the ram because it is saved in setup and even thereafter eventhough it is just a local variable, so I was wondering how to remove an array fully out of memory because it is only temporary
if you are interested in how I figured out that the still saved array is still saved and uses tons of memory well I tred running this code
and I tried running this without the array.
well as you can see example 1 uses tons of memory eventhough the array is temporary and not run twice and not needed anymore. So what I want to do is that the sketch runs as smoothly as the second does. what I already tried and didnt change anything at all is in terms of memory usage:
as well as:
Garbage Collection:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html
in short, memory is not freed immediately.
750k is NOTHING these days.
https://Forum.Processing.org/two/discussions/tagged?Tag=system.gc()
ok just for all those who ran into the same problem an easy and 100% effective way of doing this is:
-create your main sketch
-create another sketch with the memory consuming calculations into another
-add in setup() launch(sketchPath("YOUR.BAT")); ofcourse the batch file has to open the second sketch
-in the second sketch you have to save the information as string into a file saveStrings("LOCATIONOFDDATA.txt");
-then put close(); at the end of the second sketch();
-back in the main sketch you have to write
data[] = loadStrings("LOCATIONOFDDATA.txt");
then you are done and have dodged this stupid garbage collector system
I saved with this system 0.65gb ram = INTERGALACTIC PERFOMANCE BOOST
have a nice day sLucas :D