-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in Json$NullJson #27
Comments
Great catch @Macok, thanks! Will try to make a 1.4.2 patch release ASAP. |
@Macok Good catch! But I think you can not detect when the processing has ended. A user might use |
Proposed fix. @Macok could you please have a look? |
@Macok and @slaskawi thanks again for chasing this issue! Managing parents has turned out problematic in several ways - first there's multiples of them so when you do 'up' you can get an array of parents some times and others just a single parent. I couldn't think of an elegant way to deal with the ambiguity so just pushed it to the user. And now the present issue makes me realize that there is a bit of a conceptual problem as well - shouldn't all primitive values (numbers, boolean and strings) share the same parents since they are immutable and therefore should pretty much behave like reference from a user's perspective? So maybe it's a good idea to remove parents altogether and deprecate the
Other than that, @slaskawi the changes look good. If you make a PR against the 1.4 branch, I'll merge and create a 1.4.2 patch release. Thanks again! |
@bolerio I'm also a pretty big fan of parsing things top/down rather than bottom/up. Thus the As I pointed out - you never know if someone is storing a reference in a field or does everything within a method (and with a little help of escape analysis a reference might be put on stack). So I would definitely try to remove all And sure, I'll file a backport within a few minutes... |
@slaskawi: your proposed fix seems to be already in jgroups-kubernetes, correct? |
@belaban Yes! |
thx! |
@bolerio I can't see anywhere version 1.4.2 with this patch... :( |
@jacakk You are right. It hasn't been published because I've lost my credentials to publish on Maven central and I've been procrastinating sorting that problem out. But I'll do soon and mjson itself is overdue a good update too. You can of course build from the branch and install locally or on a corporate Maven repository. Many apologies for the belated reply. This got buried with a pile of github notifications. |
It looks like this is still an issue in master / 2.0? Is there any reason not to apply #29 to master? |
You are creating a
topnull
object in Json$NullJson class.static NullJson topnull = new NullJson();
This instance is static and therefore, will never be garbage collected.
Every time some json data containing null fields is processed, the
enclosing
field of this object is growing.You can reproduce the problem running this code:
Used file.json:
On the screenshot below, you can see what happens on the heap.
![leak](https://user-images.githubusercontent.com/881054/30645460-16372ad6-9e16-11e7-9e19-9c1c41a420f1.PNG)
I sequentially run multiple
Json.read()
calls and then trigger GC.After just few runs, heap size is already above 0.5GB.
Quick fix:
With @KamilKrol we introduced a quick fix, by removing the
topnull
field and creating newNullJson
instance every timeDefaultFactory#nil()
is called.This seems to be solving the leak problem, but the proper solution probably requires investigating why NullJson#enclosing field is not empty after processing is finished.
The text was updated successfully, but these errors were encountered: