Created
January 10, 2012 15:30
-
-
Save MasterLambaster/1589617 to your computer and use it in GitHub Desktop.
GC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ree-1.8.7-2011.03 | |
----------------- | |
1. Set instance value to nil | |
-------------------- Stats for Allocate -------------------- | |
Live Objects before: 4025 | |
Live Objects after: 1504032 | |
------------------------------------------------------------ | |
---------------- Stats for Set iVal to nil ----------------- | |
Live Objects before: 1504047 | |
Live Objects after: 3922 | |
------------------------------------------------------------ | |
2. Set object reference value to nil | |
-------------------- Stats for Allocate -------------------- | |
Live Objects before: 4020 | |
Live Objects after: 1504027 | |
------------------------------------------------------------ | |
-------------- Stats for set to nil/other val -------------- | |
Live Objects before: 1504061 | |
Live Objects after: 3916 | |
------------------------------------------------------------ | |
ruby-1.9.3-p0 | |
------------- | |
1. Set instance value to nil | |
-------------------- Stats for Allocate -------------------- | |
Live Objects before: 14507 | |
Live Objects after: 914514 | |
------------------------------------------------------------ | |
---------------- Stats for Set iVal to nil ----------------- | |
Live Objects before: 914530 | |
Live Objects after: 304665 | |
------------------------------------------------------------ | |
2. Stats for set to nil/other val | |
------------------- Stats for Allocate -------------------- | |
Live Objects before: 14500 | |
Live Objects after: 914507 | |
------------------------------------------------------------ | |
---------------- Stats for set to nil/other val ------------ | |
Live Objects before: 914544 | |
Live Objects after: 304667 | |
------------------------------------------------------------ | |
3. Do both set i_val to nil and object ref to nil(gc after each) | |
-------------------- Stats for Allocate -------------------- | |
Live Objects before: 14507 | |
Live Objects after: 914514 | |
------------------------------------------------------------ | |
------------------ Stats for Set iVal to nil --------------- | |
Live Objects before: 914530 | |
Live Objects after: 304665 | |
------------------------------------------------------------ | |
-------------- Stats for set to nil/other val -------------- | |
Live Objects before: 304681 | |
Live Objects after: 304665 | |
------------------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def grab_stat | |
if RUBY_DESCRIPTION =~ /Enterprise/ | |
ObjectSpace.live_objects | |
else # >= 1.9 | |
ObjectSpace.count_objects[:TOTAL] - ObjectSpace.count_objects[:FREE] | |
end | |
end | |
def gc | |
GC.enable | |
GC.start | |
GC.disable | |
end | |
GC.disable | |
class Test | |
attr_accessor :i_val | |
def initialize | |
@i_val =[] | |
300_000.times do |i| | |
@i_val << "ruby-#{i}" * 10 | |
end | |
end | |
def say_hello | |
"hello" | |
end | |
end | |
puts "-"* 20 + " Stats for Allocate " + "-" * 20 | |
puts "Live Objects before: #{grab_stat}" | |
t = Test.new | |
puts "Live Objects after: #{grab_stat}" | |
puts "-" * 60 + "\n\n" | |
puts "-"* 20 + " Stats for Set iVal to nil " + "-" * 20 | |
puts "Live Objects before: #{grab_stat}" | |
t.i_val = nil | |
gc | |
puts "Live Objects after: #{grab_stat}" | |
puts "-" * 60 + "\n\n" | |
puts "-"* 20 + " Stats for set to nil/other val " + "-" * 20 | |
puts "Live Objects before: #{grab_stat}" | |
t = [] | |
t = [1,2,3] | |
gc | |
puts "Live Objects after: #{grab_stat}" | |
puts "-" * 60 + "\n\n" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment