# Determine memeory usage of Arrays or other objects

**URL:** <https://www.ruby-forum.com/t/determine-memeory-usage-of-arrays-or-other-objects/161344>\
**Category:** Ruby\
**Created:** [February 25, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/determine-memeory-usage-of-arrays-or-other-objects/161344 "2009-02-25T18:18:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_maclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@john\_maclean](https://www.ruby-forum.com/u/john_maclean)\
**Post date:** [February 25, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/determine-memeory-usage-of-arrays-or-other-objects/161344/1 "2009-02-25T18:18:24Z")

</div>

k = [nil] \*50000

is there a way to get some idea of how much memory k will use, or even  
how much mem it may use as k.size changes?

ruby -e ‘p Array.methods.sort’ does not show anything obvious.

–  
John M.  
07739 171 531  
MSc (DIC)

Timezone: GMT

---

<div class="post-metadata">

**Author:** ![john\_maclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@john\_maclean](https://www.ruby-forum.com/u/john_maclean)\
**Post date:** [February 25, 2009, 11:00pm UTC](https://www.ruby-forum.com/t/determine-memeory-usage-of-arrays-or-other-objects/161344/2 "2009-02-25T23:00:43Z")

</div>

On 25.02.2009 18:16, john maclean wrote:

> k = [nil] \*50000
> 
> is there a way to get some idea of how much memory k will use, or even  
> how much mem it may use as k.size changes?
> 
> ruby -e ‘p Array.methods.sort’ does not show anything obvious.

And there isn’t an obvious solution. You can check the archives - this  
discussion comes up from time to time. Basically it is unclear what  
“memory taken up by an object” means. The simplest answer is the amount  
of memory that is needed to store the object itself. But what about  
references? Do you count objects in that are referenced by the Array?  
If so, how many levels do you track? Etc. You even might not find your  
memory problem by only looking at Array memory (assuming you have a  
memory issue).

Kind regards

robert
