Re: Best way to determine the memory footprint of an object



On 06/03/07, Wes Gamble <weyus@xxxxxxx> wrote:
I'd like to be able to estimate how much memory a given object requires.
What is the best/easiest way to do this? One thing that occurred to me
was the Marshal.dump the object to a file and look at that, although
looking at a textual representation of the object could be significantly
larger (I think).

Any advice is appreciated.

Take a look at object printing code in:
http://t-a-w.blogspot.com/2007/02/ruby-and-judy.html

It prints reports like:
IV Table of object Complex(1.0, 2.0)
Flags = 2
Class = Complex
IV_TBL:
* Bins: 11
* Entries: 2
* Bin 0:
* Entry
* Hash: 10802
* Key: @real
* Record: 1.0
* Bin 1: empty
* Bin 2: empty
* Bin 3: empty
* Bin 4: empty
* Bin 5: empty
* Bin 6: empty
* Bin 7: empty
* Bin 8:
* Entry
* Hash: 10810
* Key: @image
* Record: 2.0
* Bin 9: empty
* Bin 10: empty
Memory use: 88 bytes

It only works with normal objects, not anything special (like strings,
arrays, hashes, floats etc.), becuase I never needed anything else.

Object uses memory for:
* main data structure (flags, class pointer, table of instance
variables pointer)
* instance variable table
* some extra storage for non-standard objects
* associated singleton class, if any (if you include it in the count)
* instance variables are objects unless they're immediate values (if
you include them in count)
* some undefined memory allocator overhead for all of the above

--
Tomasz Wegrzanowski [ http://t-a-w.blogspot.com/ ]

.



Relevant Pages

  • bin for buzzys posts
    ... i am providing this fred as a bin for buzzy's empty dishonest posts ... it is requested that you post all your empty drivel to this one fred.... ... as a work of charity i have employed another chav to empty this bin ... it will be especially frowned upon if you put your posts in the buzzy bin ...
    (uk.politics.misc)
  • RE: XP Pro Recycle Bin is empty but still shows files icon
    ... it's just the icon that's wrong. ... Norton Protected bin. ... > (or even just after I empty the bin) the icon still shows it has files. ... > when I try to empty it again, it wants to delete my Windows directory. ...
    (microsoft.public.windowsxp.general)
  • RE: XP Pro Recycle Bin is empty but still shows files icon
    ... I can now delete files and empty the bin ... it's just the icon that's wrong. ... >> when I try to empty it again, it wants to delete my Windows directory. ...
    (microsoft.public.windowsxp.general)
  • Re: recyle bin always full
    ... then click once on the Recycle ... Bin (empty) icon, ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Memory problem
    ... the drive is 32% full or 32% empty. ... You say you deleted TIFs and ran Disk Cleanup and saw no improvement. ... are in the bin - and still using up just as much disk space as before. ... Deleting files from your HD would have NO effect on memory. ...
    (microsoft.public.windowsxp.hardware)