Determining Java Usage

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:

  • at runtime, figuring out how much memory the classes in my package are currently using
  • during development, evaluating the general utility memory requirements for various things, such as:
    • how much memory overhead is required for an empty object (in addition to the space required by its fields)
    • how much memory overhead is required when creating closures
    • how much memory overhead is required for collections like ArrayList

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)

+5
source share
8 answers

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.

+4
source

Java 5, Hotspot , , Instrumentation, VM . , . , - Java, .

Hotspot 32- :

  • 8 " "
  • , ( , , )
  • 4
  • obejct 8 (.. 1 16 ; 8 16 )

, VM . - - - . , ArrayList , 1,5, . , , " ", , .

"" - Runnable Callable, , , , . (N.B. !!)

+4

JMP, Java 1.5.

+3

profiler, Netbeans , , . .

+1

pre 1.5 VM - , . , .. .

+1

, PerfAnal , .

0

, , .

0

, , Netbeans, ,

0

All Articles