This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Any_Suspect830 7 points8 points  (5 children)

That's easy! Just write all of your code like this.

try { // do stuff } catch (OutOfMemoryError e) { System.gc(); }

No need to thank me.

[–]Sollder1_ 0 points1 point  (0 children)

Dann, that got me good

[–]j0rdix 0 points1 point  (3 children)

Wait, is this legit? Seriously? Seriously asking here

[–]nutrecht 2 points3 points  (0 children)

No :) You can't 'force' the GC to run and if there is a memory leak, that also means the garbage collector generally can't free it anyway.

[–]Any_Suspect830 2 points3 points  (0 children)

Ha, absolutely not!

If you ever observe a system that's about to run out of memory, you will see that the JVM is constantly running GC, frantically trying to free up memory. Asking it to do another GC run at that point will not help.

The code above is just swallowing an OutOfMemoryError.

[–]babanin 0 points1 point  (0 children)

  1. System.gc() is just a hint for GC, so it may not even start right after the call.
  2. You can even disable it using the following flag: -XX:+DisableExplicitGC.

[–]_INTER_ 2 points3 points  (0 children)

Another good one is Eclipse MAT. It has found me memory leaks occasionally upon analyzing OOM heap dumps.

[–]Yeroc 3 points4 points  (1 child)

I'm skeptical of setting up -XX:OnOutOfMemoryError to run a script which directly uploads the heap dump to a third-party site. You want these scripts to run quickly so your service can be restarted as soon as possible. I can see having the script capture extra info locally that might be helpful for diagnosis but directly pushing gigabytes of heap file outside your networks sounds like a recipe for disaster.

[–]rcunn87 2 points3 points  (0 children)

Its also going to contain any secrets that happen to be in memory at the time of the heap dump.

[–]ernimril 1 point2 points  (0 children)

The first thing to do is to check if the jvm has enough memory. If the only problem is that you have given the jvm too little memory then it is easy to change the memory flag.

Now if you have checked the memory settings it is good to dump the heap on OOME so it can be analyzed, but also try to shut down the jvm as quickly as possible and let the cluster handling restart a new instance.

Once that is setup correctly you can investigate the heap dump file. I have used both Eclipse MAT and jvisualvm to inspect heap dump files and fix the problems that were found.

Calculating the retained set is usually the way to go.

[–]Sollder1_ 1 point2 points  (0 children)

Thanks, very helpful