Skip to content

Instantly share code, notes, and snippets.

@ppelleti
Last active August 29, 2015 14:09
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 ppelleti/cbe10a087f4d6cecdaeb to your computer and use it in GitHub Desktop.
Save ppelleti/cbe10a087f4d6cecdaeb to your computer and use it in GitHub Desktop.
demonstrate leak in LIFX gem
#!/usr/bin/ruby
gem 'lifx'
require 'lifx'
start_time = Time.now.to_i
prev_objs = ObjectSpace.count_objects
lifx = LIFX::Client.lan
lifx.discover!
light = lifx.lights.first
loop do
temp_c = light.temperature
temp_f = temp_c * (9.0 / 5.0) + 32
GC.start # so we only count live objects
objs = ObjectSpace.count_objects
print "\nElapsed time: ", Time.now.to_i - start_time, " seconds\n"
print "Temperature: #{temp_c} C #{temp_f} F\n\n"
objs.each do |type, count|
delta = (count || 0) - (prev_objs[type] || 0)
printf "%10s => %8d delta %8d\n", type, count, delta
end
prev_objs = objs
sleep(600)
print "\n============================================================\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment