Comments (3)
yeah there's no memory leak here, valgrind (with and without massif) report nothing and I don't think DRS is exactly something you can go off of (IF that's what you're looking at, sorry, I was noticing this staying high with DRS but not RSS), since it seems to be very different from what massif and kde's system monitor report to me (these 2 are similar, showing a drop to ~800kb-1.2mb after the calls to free
)
I'd like to guess that it's the system either reserving that memory for further reuse for that process, or it could be some other OS-level oddity, not sure
from tree-sitter.
I managed to track down what the issue I'm seeing is. @amaanq You are right that this is not a memory leak. It seems that the memory is being free, but not released to the OS, which is why memory profilers do not see an issue.
If we change the program to this:
use tree_sitter::{Parser};
use libc;
fn main() {
let source_code = "fn main() {}\n".repeat(100000).to_string();
let mut parser = Parser::new();
parser
.set_language(tree_sitter_rust::language())
.expect("Error loading Rust grammar");
let tree = parser.parse(source_code, None).unwrap();
drop(tree);
drop(parser);
// Release free memory in the heap.
unsafe {libc::malloc_trim(0);}
loop {
// Sleep every 10 miliseconds to prevent high CPU usage
let ten_millis = std::time::Duration::from_millis(10);
std::thread::sleep(ten_millis);
}
}
We call malloc_trim
to release the memory within the heap. Although far from an ideal solution due to the usage of unsafe
code, almost all of the memory gets released to the OS and my System Monitor shows very low memory.
from tree-sitter.
The default allocator is libc's for tree-sitter, but you can set your own allocator with ts_set_allocator
if you prefer something that holds onto memory for reusage less aggressively. You can also avoid pulling in libc for malloc_trim
by playing with the env var M_TRIM_THRESHOLD
or MALLOC_TRIM_THRESHOLD_
- https://www.gnu.org/software/libc/manual/html_node/Malloc-Tunable-Parameters.html
from tree-sitter.
Related Issues (20)
- exernal scannar
- Allow parsers to manually return errors
- Add type definitions to language bindings HOT 3
- Add Node.js prebuilds to language grammars HOT 5
- npm publish access for tree-sitter-haskell HOT 6
- Binding rust : Query wrapper doesn't take ownership of the source, or doesn't reference it with a lifetime
- ts_set_allocator is no longer an external symbol HOT 3
- Tree-sitter predicates backward compatibilty HOT 2
- Versioning Conflict for Grammars' Rust Bindings HOT 2
- [question] is is possible to format code using tree-sitter? HOT 1
- Can you help me explain this `optional()` + `prec.left()` behavior? HOT 1
- "expected &Language, found Language" in generated rust bindings on 0.21.0 HOT 5
- Unnecessary warnings about unsupported regexp flags HOT 3
- Add `sym.deref` function for getting the actual node the symbol refers to
- tree-sitter.DLL is missing almost all exports HOT 4
- Incorrect query captures HOT 1
- `token.immediate` stops working when there's a `$._whitespace` node
- tree-sitter generate only produces node and rust bindings HOT 1
- Possible off-by-one error when using `ts_node_field_name_for_child` HOT 6
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 tree-sitter.