finding total number of bytes an object takes up

Discussion in 'Java' started by kvnsmnsn@hotmail.com, Nov 3, 2006.

  1. Guest

    Given an object of a Java class, is there some straightforward way to
    find out how many bytes of memory it takes up?

    In C there exists a <sizeof()> operator, but even if it had a counter-
    part in Java (which doesn't appear to be the case) that wouldn't be
    exactly what I want because the objects I want to know the sizes of
    contain references to objects of other classes, and I need to know the
    _total_ bytes taken up by that object, its components, its components'
    components, and so on. Can anybody point me to how I can find this
    out? Any information would be greatly appreciated.

    ---Kevin Simonson

    "You'll never get to heaven, or even to LA,
    if you don't believe there's a way."
    from _Why Not_
    , Nov 3, 2006
    #1
    1. Advertising

  2. Daniel Dyer Guest

    On Fri, 03 Nov 2006 21:49:26 -0000, <> wrote:

    > Given an object of a Java class, is there some straightforward way to
    > find out how many bytes of memory it takes up?
    >
    > In C there exists a <sizeof()> operator, but even if it had a counter-
    > part in Java (which doesn't appear to be the case) that wouldn't be
    > exactly what I want because the objects I want to know the sizes of
    > contain references to objects of other classes, and I need to know the
    > _total_ bytes taken up by that object, its components, its components'
    > components, and so on. Can anybody point me to how I can find this
    > out? Any information would be greatly appreciated.


    This is a frequently-asked question and has been covered on here a few
    times in the last month or so. There was even a JavaWorld link posted by
    Hendrik Maryns today. If you search the c.l.j.p Google Groups archive for
    'sizeof' you should find something.

    Dan.

    --
    Daniel Dyer
    http://www.uncommons.org
    Daniel Dyer, Nov 3, 2006
    #2
    1. Advertising

  3. Daniel Dyer wrote:
    > This is a frequently-asked question and has been covered on here a few
    > times in the last month or so. There was even a JavaWorld link posted
    > by Hendrik Maryns today. If you search the c.l.j.p Google Groups
    > archive for 'sizeof' you should find something.


    The last one started October 25th and the subject
    is "Memory Footprint of an Object".

    Arne
    =?UTF-8?B?QXJuZSBWYWpow7hq?=, Nov 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Collins
    Replies:
    3
    Views:
    5,995
    Jason Collins
    Feb 18, 2004
  2. Asad
    Replies:
    3
    Views:
    340
    Darren Clark
    Apr 27, 2004
  3. mrby

    4-bytes or 8-bytes alignment?

    mrby, Nov 2, 2004, in forum: C Programming
    Replies:
    8
    Views:
    404
    Mark McIntyre
    Nov 2, 2004
  4. Replies:
    5
    Views:
    519
    Flash Gordon
    Apr 9, 2006
  5. sfs
    Replies:
    3
    Views:
    294
Loading...

Share This Page