Open jkylling opened 2 months ago
How do you think this solution compares to #494 ?
How do you think this solution compares to #494 ?
I have not looked at #494 in detail, but I believe it allows accidentally dropping one of the parsers while keeping the other one. That would render the remaining parser unusable. The API should try to prevent accidental misuse if possible.
By using
recursive_2
orrecursive_fold
instead ofRecursive::declare
we can prevent situations where we either keep too many strong references around, leading to memory leaks, or too few strong references around, leading to broken parsers because all the strong references and the parsers are dropped.We could consider removing
Recursive::declare
from the public API, since it is hard to use it correctly.Please see the investigation (for version 0.9) in https://github.com/zesterer/chumsky/issues/486#issuecomment-2198514803
If code is migrated to use
recursive_2
orrecursive_fold
we should be able to resolve https://github.com/zesterer/chumsky/issues/486 I have tested that this patch for 0.9 fixes the memory issue on jaq when repeatedly creating parsers.