Comments (5)
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.
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.
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.
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.
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)
- "sh: END_OF_RUBYCODE: not found" "sh: 2>&1: not found" "sh: : cannot execute" on Solaris HOT 8
- On Solaris, The DATA constant succeeds in locking the file DATA came from FAILED HOT 4
- Make a gem release for forked mspec project HOT 14
- Support mruby HOT 13
- uninitialized constant MSpecOptions::SummaryFormatter in ruby ci HOT 1
- Use another framework for the tests/specs of mspec itself HOT 8
- MinGW and parallel tests HOT 18
- Allow any formatter when running in parallel (-j)
- Improve communication of parallel mspec
- Combining guards HOT 11
- mspec :foobar raises a ZeroDivisionError HOT 1
- Limitations of it_behaves_like HOT 1
- Randomly failing spec HOT 3
- config files HOT 4
- Add guards for mswin or mingw? HOT 2
- Guards with multiple criteria HOT 13
- ruby_bug FROM...TO HOT 1
- Update documentation link in readme HOT 1
- Error: -e:1: `$(' is not allowed as a global variable name on OSs whose /bin/sh is not bash. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mspec.