If you're not using str anywhere after then it's just that the garbage collector has not run so the memory that should be released hasn't been collected yet. This is probably because Java doesn't need it (since it has some reserve pages left) yet as Java has to use a certain amount of memory before it starts reclaiming memory since running the garbage collector is an expensive task.
If you're not using str anywhere after then it's just that the garbage collector has not run so the memory that should be released hasn't been collected yet. This is probably because Java doesn't need it (since it has some reserve pages left) yet as Java has to use a certain amount of memory before it starts reclaiming memory since running the garbage collector is an expensive task.
I'm going to assume that you do not keep references to the strings you create.
Basically, that call creates a new object every time it runs. Those objects remain in memory until the Java Virtual Machine decides to perform garbage collection. The JVM will not do so until it decides that it is necessary. Necessary is generally when your memory usage exceeds a certain threshold. That threshold will depend on your machine and the setting the JVM was started with.
Videos
First one is correct. There is no memory leak, by the way.
--
I think sprintf is C. Is there a better way?
Yes. C++ way:
std::stringstream ss; //#include <sstream>
ss << fCount;
std::string frameNum = ss.str();
7, as sprintf will append a null byte '\0' to the end of the string.