Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verifying parent nodes' existence #2488

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

jnamika
Copy link
Contributor

@jnamika jnamika commented Nov 14, 2024

Fix #2487

Since the loop over self.nodes.iter() in GraphMemoryManagement::clear_unused_roots() does not process nodes in child-to-parent order, if a node's parents are removed first, that node will not be deleted and will remain. To address this, I added a check to verify if all parents are absent from self.nodes. If none of the parents exist in self.nodes, the node is treated as having no parents and is marked for deletion.

@@ -84,7 +84,10 @@ impl GraphMemoryManagement {
for (id, parents) in self.nodes.iter() {
let is_useful = matches!(self.statuses.get(id), Some(NodeMemoryStatus::Useful));

if !is_useful && Arc::strong_count(id) == 1 && parents.is_empty() {
let parents_absent =
parents.is_empty() || parents.iter().all(|p| !self.nodes.contains_key(p));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If parents.is_empty() == true, parents.iter().all(...) == true. If the second expression works, the first expression i.e. is_empty has no effect.

https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially kept parents.is_empty() to reflect the intended logic, but you are absolutely correct that it has no effect here. I’ll go ahead and make that adjustment. Thanks again!

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.91%. Comparing base (c7233bf) to head (5c91918).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2488   +/-   ##
=======================================
  Coverage   82.91%   82.91%           
=======================================
  Files         812      812           
  Lines      105334   105336    +2     
=======================================
+ Hits        87336    87338    +2     
  Misses      17998    17998           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@AsherJingkongChen AsherJingkongChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I used my project as "my" example program to test your changes.

I used Apple's Instruments.app to profile heap memory every 10 seconds, below are the results:

  • c7233bf: 9 of 11 snapshots has leaks
  • 5c91918: 0 of 12 snapshots has leaks

It indicates that your changes work for me.

I think the moderators can merge it.

Miscellaneous

As for MNIST example, I don't know why I can't run it with:

./target/debug/examples/mnist

It looks like I messed up $DYLD_LIBRARY_PATH again.

Copy link
Member

@laggui laggui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for both flagging the issue and fixing it 🎉

@AsherJingkongChen thank you also for validating

@laggui laggui merged commit 1cd956e into tracel-ai:main Nov 14, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory Leak and Performance Degradation in GraphMemoryManagement due to Unreleased Nodes
3 participants