dominictarr / crdt

Commutative Replicated Data Types for easy collaborative/distributed systems.
MIT License
836 stars 43 forks source link

Memory disposal #17

Open Raynos opened 11 years ago

Raynos commented 11 years ago

Should crdt listen to the dispose event and purge it's history / memory when it occurs.

How else would I say doc.destroy() to indicate the document is no longer necessary and I want to release the memory.

dominictarr commented 11 years ago

dispose kills all the streams, so there won't be external references to it... there should never be references coming from the objects in history to anything else (or vice versa) so once the streams are disconnected, it should get GCed.

Raynos commented 11 years ago

@dominictarr that assumes all references to Row's are GC'd. That's a big assumption.

dominictarr commented 11 years ago

hmm, okay, so maybe we want to call removeAllListeners() after next tick on all the rows and sets. history doesn't contain references to any Row, just the ids of the rows they pertain to.

Raynos commented 11 years ago

or! loop all rows null out .state. null out .sets and .hist null out ._events done!

dominictarr commented 11 years ago

that is messy! I want a test for this. As I said, you don't need to null hist, because there will be no references to it.

You'll need to find some documentation on triggering GC in javascript, or some sort of test case, I guess using weak-map, if you want to convince me this is a good idea.

Raynos commented 11 years ago

@dominictarr I don't want to rely on GC nor my ability to not leak memory with closures when using scuttlebutt on the server. I just want to nuke old docs that are no longer relevant

dominictarr commented 11 years ago

Well, you are welcome to do that, but I am not bringing code into crdt unless it can be demonstrated to work.