Technical Discussion: Memory Deallocation Strategy for Node and its Dependencies #16
Replies: 1 comment
-
I believe the core question here is who owns what. TL;DR: I think the most sensible approach for this is to just use reference counting and make every user increase and decrease the count as needed (by calling a function made to that end). You would also need some kind of mutex, that may be the most costly part. |
Beta Was this translation helpful? Give feedback.
-
Memory Deallocation Strategy for Node and its Dependencies
Background
In our current implementation of the
Node
struct, we have dependencies likeMempool
,Storage
,P2P
, andRPC
. These components are initialized outside theNode
and passed in during its initialization. Currently, theNode
struct'sdeinit
function doesn't handle the deallocation of these dependencies.Current Implementation
The Question
Should the
Node
struct be responsible for deallocating its dependencies (Mempool, Storage, P2P, RPC) in itsdeinit
function?Considerations
Ownership and Responsibility:
Node
could be seen as the owner of these components, making it logical for it to handle their cleanup.Miner
) also use these components.Lifetime Management:
Node.deinit()
could simplify lifetime management.Node
.Flexibility and Reusability:
Thread Safety and Race Conditions:
Node
impact thread safety, especially if components are shared?Error Handling:
Node
is responsible?Testing and Mocking:
Node
and mock its dependencies?Zig Best Practices:
Performance Considerations:
Possible Approaches
Node.deinit()
to deallocate all dependencies.Node
deallocates some components but not others.Node
during initialization.Questions for Discussion
Next Steps
Please share your thoughts, experiences, and any additional considerations we should take into account. Your input will help us make an informed decision that balances safety, performance, and maintainability.
Beta Was this translation helpful? Give feedback.
All reactions