BUG: Memory-leak on streaming queries when LoadBuffers are not aligned #2936
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello Rob, unfortunately, we discovered a second problem with memory leaks in streaming queries.
This happens, when LoadBuffers are involved.
Normally the loadBuffer holds references up to
batchSize
(default=10) beans. The beans itself holds references to BeanLists, which holds references to the load buffers. This is a cycle, but normally not critical, as there is a cut every batch.If multiple load buffers are involved, we have luck, as long there are correctly aligned and do not "overlap". This overlap may happen if beans have different layouts (e.g. inherited beans)
In the test case, I've created ONE TestModel3A bean here, that has the "many2" property missing.
So when the first "findEach" loads the bean, the
many1
property has a buffer of 10 belonging to the beans BBBBBABBB and all of them refer back to the same load context. But inmany2
there are 10 A beans and the last bean holds a reference to a different load-context. They all build a "chain", so that they cannot be gc'ed.I've written a test, that fails with -Xmx100m in findEach
@rbygrave How do you think should we fix these issues. Should we introduce weak references in loadContext or do you see other options like skipping the non existent property
many2
in TestModel3A, so that the loadcontext will be properly aligned