Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on basic operations #8

Open
dinedal opened this issue Sep 17, 2013 · 3 comments
Open

Memory leak on basic operations #8

dinedal opened this issue Sep 17, 2013 · 3 comments

Comments

@dinedal
Copy link
Collaborator

dinedal commented Sep 17, 2013

require 'leveldb'

db = LevelDB::DB.new("/tmp/leaktest")

GC.start
puts GC.stat

10000.times do
  db.get('foo')
  GC.start
end


puts GC.stat

Sample output:

{:count=>7, :heap_used=>897, :heap_length=>4422, :heap_increment=>1964, :heap_live_num=>28158, :heap_free_num=>336751, :heap_final_num=>0, :total_allocated_object=>207656, :total_freed_object=>179498}
{:count=>10007, :heap_used=>620, :heap_length=>4422, :heap_increment=>1964, :heap_live_num=>28165, :heap_free_num=>224051, :heap_final_num=>0, :total_allocated_object=>367680, :total_freed_object=>339515}

Just for db.get on a nonexistant key 10,000 times, looks like there were 160024 allocated objects that can not get freed

DAddYE added a commit that referenced this issue Sep 18, 2013
@DAddYE
Copy link
Owner

DAddYE commented Sep 20, 2013

Can you confirm that with the latest release are we all good?

@atomical
Copy link

atomical commented Nov 7, 2013

I'm still seeing a leak. Is there a pointer that isn't being free'd?

@abargnesi
Copy link

This GC test is incorrect. The total_freed_object count increases proportional to the total_allocated_object count indicating that allocated objects are being collected.

Also keep in mind that GC.start will not execute a full mark and sweep unless you run GC.start(full_mark: true, immediate_sweep: true).

If you use ObjectSpace.count_objects you can see proper garbage collection. Going further you can dump all objects using ObjectSpace.dump_all(output: open('heap.json', 'w')) and you will see only a handle full of differences.

#!/usr/bin/env ruby

require 'leveldb'
require 'objspace'

db = LevelDB::DB.new("/tmp/leaktest")

GC.start(full_mark: true, immediate_sweep: true)
puts ObjectSpace.count_objects
# {
#     :TOTAL=>92121,
#     :FREE=>44550,
#     :T_OBJECT=>4539,
#     :T_CLASS=>1549,
#     :T_MODULE=>88,
#     :T_FLOAT=>6,
#     :T_STRING=>25147,
#     :T_REGEXP=>342,
#     :T_ARRAY=>8794,
#     :T_HASH=>387,
#     :T_STRUCT=>34,
#     :T_BIGNUM=>2,
#     :T_FILE=>3,
#     :T_DATA=>4074,
#     :T_MATCH=>1,
#     :T_COMPLEX=>1,
#     :T_RATIONAL=>1,
#     :T_NODE=>2469,
#     :T_ICLASS=>134
# }

100000.times do
  db.get('foo')
end

GC.start(full_mark: true, immediate_sweep: true)
puts ObjectSpace.count_objects
# {
#     :TOTAL=>92121,
#     :FREE=>44528,
#     :T_OBJECT=>4539,
#     :T_CLASS=>1549,
#     :T_MODULE=>88,
#     :T_FLOAT=>6,
#     :T_STRING=>25171,
#     :T_REGEXP=>341,
#     :T_ARRAY=>8793,
#     :T_HASH=>389,
#     :T_STRUCT=>34,
#     :T_BIGNUM=>2,
#     :T_FILE=>3,
#     :T_DATA=>4074,
#     :T_MATCH=>1,
#     :T_COMPLEX=>1,
#     :T_RATIONAL=>1,
#     :T_NODE=>2467,
#     :T_ICLASS=>134
# }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants