How do you know the size of the object(s) in memory?



  • I need to know how many bytes in my operational memory is a collection in my annex.ArrayList) I need this to imagine how many objects I can add without having OutOfMemory

    I'd like to know if there's a way to read the manual.

    Specifically, I have solved my problem, but the issue remains open, because my solution is not related to the determination of the level of memory of the object.
    So, I just decided to check in practice how many objects without problems can be remembered from different phone models.

    java.lang.instrument Android (Dalvic/ART) does not exist.



    1. The simplest way to do it. Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() Before the big test collection is established, after. Repeat several times to avoid accident.
    2. It's harder to use. https://stackoverflow.com/q/9368764/4318868 etc. to determine the size of the medium object in the collection and to quote the collection size.

      By myself. ArrayList only 4(8) bytes per cell (in total) Dependency on the size of the indicator, even in 64 battle systems indicators can be 4 byte), i.e. the main memory costs to be specific to the objects contained in ArrayList♪ But the definition of the size of the Java facility is complicated because it doesn't make sense what to think. If the size of the field itself is considered to be very small, the size of the objects will be considered to be small, including all the objects to which the objects are referred, many objects may be referred to one common facility and counted several times (more all objects in the system may be invoked to each other and the size of any object may be counted as equal to all the objects of the system). So the first way is preferable.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2