Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Grabage Collector in ruby, Why should I care ?

Grabage Collector in ruby, Why should I care ?

Ruby GC talk for Deccan ruby conf

Aboobacker MK

August 12, 2017
Tweet

More Decks by Aboobacker MK

Other Decks in Programming

Transcript

  1. 2

  2. 4

  3. 5

  4. 6

  5. 7

  6. 8

  7. 9

  8. 10

  9. 12

  10. 13

  11. 14

  12. 16

  13. 17

  14. 18

  15. module GC def self.run mark sweep end def self.mark root_objects.each

    do |root_obj| root_obj.associated_objects.each do |object| obj.update(marked: true) end end end def self.sweep objects.where(marked: false).destroy_all objects.update_all(marked: false) end end 19
  16. 20

  17. 21

  18. 22

  19. 24

  20. 25

  21. 26

  22. module GC def self.run objects.update_all(color: white) clearly_living_objects.update_all(color: grey) objects.where(color: grey).each

    do |object| object.references.update_all(color: grey) object.update(color: black) end objects.where(color: white).destroy_all end end 27
  23. 28

  24. 29

  25. 30

  26. 31

  27. 32

  28. 100_000.times do foo = "a string" end RETAINED = []

    100_000.times do RETAINED << "a string" end 34
  29. Model.all.each do |item| process(item) end Model.find_each do |item| process(item) end

    Model.select(:id,:other, :necessary, :attributes) 35 . 1
  30. class Thing; end list = Array.new(1000) { Thing.new } list.each

    do |item| puts item end list = nil class Thing; end list = Array.new(1000) { Thing.new } while list.count > 0 puts list.pop end 35 . 2
  31. 36

  32. 37

  33. 38