Forum: Ruby Determine memeory usage of Arrays or other objects

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Acd90f2627e42cf3727fed4dfb347c1e?d=identicon&s=25 john maclean (Guest)
on 2009-02-25 18:18
(Received via mailing list)
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 Maclean
07739 171 531
MSc (DIC)

Timezone: GMT
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-02-25 23:00
(Received via mailing list)
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
This topic is locked and can not be replied to.