-
almost infinite loop
Hi,
If I do something like this,
int var;
byte [] b = null;
while(1){
read var;
b = new byte[var]
//process b
}
will the program ever run out of memory. Will it create a new location everytime, the new stmt is executed. Will the old location be out of scope and dumped or stays hanging there without being used as long as the program doesn't exit
The code is from java, but I want the concept clear.I did not show the full code, it assumes that while exits when program is shut down using ctrl-c or likewise.
Thanks ,
Future member.
-
this program will cause infinte loop , which will occure new location every time . and these ll not be cleared from memory as your program ll not close....................
hope I helped you .......moemen ahmed
-
That code is totally memory leaky.
-
Java does garbage collection. That's why that works in Java.
C and C++ do not. This concept creates a memory leak, where the memory is allocated but there is no way to access it anymore.
In a language with garbage collection, the garbage collector runs and is able to free up any memory that no longer has a way to be accessed. The new C# language does this as well, but good old C/C++ we get to do it ourselves.