Skip to content

Instantly share code, notes, and snippets.

@djsun
Created August 17, 2010 16:08
Show Gist options
  • Save djsun/530570 to your computer and use it in GitHub Desktop.
Save djsun/530570 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo'
class MongoLeakFinder
def initialize
db = Mongo::Connection.new.db("cgp")
@coll = db.collection("records")
@coll.create_index("n", :unique => true)
end
MAX = 1_000_000_000
def run
n = 0
loop do
puts "%09i" % n
@coll.find("n" => n)
n += 1
n = 0 if n >= MAX
end
end
end
@djsun
Copy link
Author

djsun commented Aug 17, 2010

Note: I already have objects in the cgp database with the "n" key.

@djsun
Copy link
Author

djsun commented Aug 17, 2010

On my system, this code does not seem to have any space leak. Real memory usage varies between 22.1 MB and 23.1 MB. (Garbage collection apparently kicks in at 23.1 and brings it down to 22.1.)

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