Skip to content

Instantly share code, notes, and snippets.

@be9
Last active November 17, 2015 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save be9/9663ff65338cd2d074bc to your computer and use it in GitHub Desktop.
Save be9/9663ff65338cd2d074bc to your computer and use it in GitHub Desktop.
def fill(a)
100_000.times {
a << rand(10000).to_s * 100
}
end
def aa
ary = []
fill(ary)
end
def bb
Object.const_set("ARY", [])
fill(ARY)
end
GC.start
puts GC.stat[:heap_live_slots]
aa
puts GC.stat[:heap_live_slots]
GC.start
puts GC.stat[:heap_live_slots]
bb
puts GC.stat[:heap_live_slots]
GC.start
puts GC.stat[:heap_live_slots]

7532

123737

Здесь aa насоздавала объектов.

7533

После запуска GC всё освободилось.

145586

Здесь bb насоздавала объектов.

107535

100 тысяч объектов осталось (освободились только промежуточные результаты).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment