Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5417

Memory leak when using with()

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0, 8.0.3, 7.5.2
    • Affects Version/s: 7.0.13, 7.1.11, 7.2.6, 7.3.4, 7.4.0
    • Component/s: None
    • None

      Hello!

        I have found following strange behavior. Every time, when with() method is used, new Symbol is created and never released. Please, find sample code below.

      Model:

      class TestMemLeak
        include Mongoid::Document

        field :processed, type: Boolean, default: false
      end

       

      In controller:

      def test_action

          GC.start()
          puts Symbol.all_symbols.size
          test_mem_leak.with(write: {w: 0, j: false}){|t| t.set(processed: true) }
          GC.start()
          puts Symbol.all_symbols.size

      end

       

      After execuring  line 

         test_mem_leak.with(write: {w: 0, j: false}){|t| t.set(processed: true) }

      a number of symbols is always increased by one and never decreased by GC.

      After replacing line above by this one:

       t.set(processed: true) 

      issue cannot be reproduced anymore.

       

      Tested on Ruby 2.7.2,  Rails 6.1.6.

      Best Regards,

      Ilya

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            istarovoytov@gmail.com Ilya Starovoytov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: