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

Memory leak: fix the cyclic-ness of the DAG #1010

Closed
mratsim opened this issue May 12, 2020 · 5 comments
Closed

Memory leak: fix the cyclic-ness of the DAG #1010

mratsim opened this issue May 12, 2020 · 5 comments

Comments

@mratsim
Copy link
Contributor

mratsim commented May 12, 2020

The DAG has cycles on BlockRef but it is tagged {.acyclic.}.

With the default refcounting GC, it's a guaranteed memory leak as acyclic means "trust me, you don't need to run cycle detection" to the GC.

https://github.com/status-im/nim-beacon-chain/blob/9636ca3e17628d4bfbdc2a29006e5385fc398e66/beacon_chain/beacon_node_types.nim#L158-L172

Either we lose the {.acyclic.} tag (which means BlockRef alloc/dealloc will trigger both refcounting and mark-and-sweep). Or we remove either the parent field or the children field.

Using pointers for weak ref is not possible as the GC can relocate ref objects in memory and invalidate the pointer and {.cursor.} is for GC:ARC.

@stefantalpalaru
Copy link
Contributor

the GC can relocate ref objects in memory

Only a compacting GC would do that, right?

@mratsim
Copy link
Contributor Author

mratsim commented May 12, 2020

Nim GC does relocate refs and I was bitten by it:

I tried this: nim-lang/Nim#9974

but in the end it led to very hard to investigate bugs in my DAG and I had to remove ptr (mratsim/Arraymancer@30749e5)

The worse is that when the ref was moved, it was replaced not by uninitialized or invalid memory that would crash but by another valid ref.

To detect that I had to print my DAG link and then i realize that I was somehow not jumping from child to parent but there were missing links.

@arnetheduck
Copy link
Member

don't sweat it: #669

@stefantalpalaru
Copy link
Contributor

Just remove the {.acyclic.} pragma. Who knows how much time will pass until the complete removal.

@arnetheduck
Copy link
Member

indeed.

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

No branches or pull requests

3 participants