Hmmm. Is there any tutorial on memory usage in Java? I would have thought that Sun or IBM would have a good article on this subject, but I can not find anything that would look very solid. I am interested to know two things:
I can have hundreds of thousands of objects created, and I want to be a "good neighbor" so as not to waste RAM too much. I mean, I don’t care if I use 10% more memory than the “best case” (whatever that may be), but if I implement something that uses as much memory as possible 5 times, if I made a simple change, I would like to use less memory (or be able to create more objects for a fixed amount of available memory).
I found several articles ( Java Specialist Newsletter and something from Javaworld ) and one of the built-in classes java.lang.instrument.getObjectSize () that claims to measure the “approximation” (??) of memory usage, but they all seem vague ...
(and yes, I understand that a JVM running on two different operating systems can probably use different amounts of memory for different objects)
I used JProfiler a few years ago, and it did a good job, and you can break the memory usage to a rather granular level.
Java 5, Hotspot , , Instrumentation, VM . , . , - Java, .
Hotspot 32- :
, VM . - - - . , ArrayList , 1,5, . , , " ", , .
"" - Runnable Callable, , , , . (N.B. !!)
JMP, Java 1.5.
profiler, Netbeans , , . .
pre 1.5 VM - , . , .. .
, PerfAnal , .
, , .
, , Netbeans, ,