Giter Club home page Giter Club logo

Comments (5)

eregon avatar eregon commented on July 30, 2024

And since that symbol is used as method, even if the method gets erased, the symbol remains.

Isn't the cause of the memory leak a bug/limitation of CRuby then?

from mspec.

MaxLap avatar MaxLap commented on July 30, 2024

I'm not sure how to qualify it.

It's a documented behavior and you can even see how many immortal symbols you have.

3.2.3 :003 > require 'objspace'
3.2.3 :003 > ObjectSpace.count_symbols
 => {:mortal_dynamic_symbol=>7, :immortal_dynamic_symbol=>66, :immortal_static_symbol=>7799, :immortal_symbol=>7865}
3.2.3 :004 > 1000000.times { |i| a = Object.new; a.singleton_class.alias_method(:"tic_#{i}", :to_s) }
 => 1000000
3.2.3 :005 > ObjectSpace.count_symbols
 => {:mortal_dynamic_symbol=>7, :immortal_dynamic_symbol=>1000066, :immortal_static_symbol=>7803, :immortal_symbol=>1007869

A memory leak in C++ is normally not considered a bug in C++ itself, it's the programmer or library not freeing memory. This behavior here is a programmer doing something that is documented to not release the memory without any attempt at reusing the same memory each time.

In any case, I think it makes sense to limit the triggering of that behavior in a low-level tool such as mspec.

from mspec.

eregon avatar eregon commented on July 30, 2024

CRuby is holding onto a Symbol the user is no longer holding onto, so IMO it's a CRuby bug and worth reporting.
e.g. maybe method names should be :mortal_dynamic_symbol.
I would think there is no such issue on TruffleRuby for instance.
This also means CRuby cannot properly GC code and would be subject to DoS if loading unlimited amounts of dynamically-generated code.

This behavior here is a programmer doing something that is documented to not release the memory

Is it documented as in part of some documentation?

I'm not against working around this in mspec though, so PR welcome as long as it keeps things simple.

Also do you know how big of a memory leak does it cause in practice?
I have never noticed this being an issue when running ruby/spec for example.

from mspec.

MaxLap avatar MaxLap commented on July 30, 2024

Here is some talking about it for ruby 2.7: https://ruby-doc.org/core-2.7.1/doc/security_rdoc.html#label-Symbols. It's kind of hard to find any doc about up to date ruby at all... I don't know why.

In practice, you won't notice. Unless you are me who is trying to run ruby/spec specs many many time to try to notice actual memory leaks :). Then mocks means an unusable test for that purpose.

I'll look into a PR. Thanks!

from mspec.

eregon avatar eregon commented on July 30, 2024

Thanks, that's clearly documented, I didn't know.
Not sure why such Symbols are not GC'd but it probably simplifies the global method cache or so.
FWIW the link to the master version of that: https://docs.ruby-lang.org/en/master/security_rdoc.html#label-Symbols

from mspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.