Hi!
We just ran into an issue with VibeManualMemoryManagement that's as follows:
We are taking a query string parameter as found in the HTTPServerRequest.query associative array, and storing it in a table whose lifetime is global. In some cases, the value was being overwritten by the next request that reused the memory, but in others it was fine.
After a while reading through vibe's code, it was clear that the inconsistency was because formDecode() uses fresh GC memory if decoding has actually taken place. So for parameters with spaces or any sort of non-url characters, it would be fine.
I haven't read through all the code, but I suspect anything that comes out of a HTTPServerRequest cannot be trusted to have a lifetime longer than the request itself, which means appending .dup() to anything that will get stored.
This is problematic, because for example, in the case where formDecode() uses the appender, .dup() would be redundant and a pessimization.
For now, I removed VibeManualMemoryManagement from our dub.json, and will monitor GC activity to see if we can live with it for the time being.
Does it make sense?
Should we do anything to improve the situation? I think at least mentioning it in the documentation could help a bit.
I was wondering if instead of using appenders for the decoding, etc..., we could just allocate a little extra memory per request, and do any decodings in there until it's full. This way, the limitation is clear, and no memory is safe past the request's life-time.
To enforce it, we could set the memory to 0x00 or 0xdd at the end of the request, in debug builds.
Everyone who choses to use VibeManualMemoryManagement would have to understand this limitation, but the good thing is that any .dup's won't be redundant.
Any other ideas?