-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
puts "memory usage at start %d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
||
str = 'x' * 1024 * 1024 * 10 # 10 MB | ||
|
||
puts "memory usage after allocation %d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
||
str = nil | ||
GC.start(full_mark: true, immediate_sweep: true) | ||
|
||
puts "memory usage after GC %d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# require 'pretty_print' | ||
require 'pp' | ||
|
||
def stats | ||
GC.stat.select { |k, v| %i(count heap_allocated_pages).include?(k) } | ||
end | ||
|
||
# ------ main ------ | ||
|
||
GC.start | ||
|
||
puts "\tBefore allocation" | ||
pp stats | ||
|
||
x = Array.new(15_000) { Object.new } | ||
|
||
puts "\tAfter 15.000 small objects allocation" | ||
pp stats | ||
|
||
x = nil | ||
|
||
puts "\tAfter 15.000 small objects finalized" | ||
pp stats | ||
|
||
y = Array.new(15_000) { Object.new } | ||
|
||
puts "\tAfter 15.000 more small objects allocation" | ||
pp stats | ||
|
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