10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyでのメモリ使用量調査

Last updated at Posted at 2015-08-07

このオブジェクトがどれ程のバイト数使っているか知りたい

Ruby でラインメモリプロファイラ
http://qiita.com/sonots/items/c14b3e3ca8e6f7dfb651
http://docs.ruby-lang.org/ja/2.2.0/method/ObjectSpace/m/memsize_of.html

ObjectSpace.memsize_of(obj)

を使えばとれるのか。
しかし obj が Hash の場合、データ数が同じだと中のオブジェクトが異なるけど同じバイト数が出ている…?

→参照先のオブジェクトのバイト数は見に行っていないのかなと推測。

じゃあ今の全てのオブジェクトのバイト数がわかるか?

ObjectSpace.memsize_of_all

であっさり取れる。
直前に GC.start できればある程度正確になるかと。

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?