Does the JVM save memory on the system? If so, how to clean it?

I am running the application using NetBeans and in the project properties. I installed a bunch of Max JVMs in 1 GiB.

But still, the application crashes from memory.

Does the JVM have memory stored on the system? If so, how to clear this memory?

+4
source share
6 answers

As @camobap mentioned, OutOfMemory's reason was that the Perm Gen size was set very low. Now the problem is resolved.

Thanks to everyone for the answers and comments.

+3
source

You want to analyze your code with a profiler - Netbeans has a good one. This will show you where the memory is tied in your application, and should give you an idea of ​​where the problem lies.

The JVM will garbage collect objects as much as it can before the memory runs out, so most likely you are holding onto the links after you no longer need them. Either this, or your application is really one that requires a lot of memory, but I would say that this is most likely to be an error in your code, especially if the problem occurs only after the application has been launched for a long period of time.

+6
source

I do not fully understand all the details of your question, but I think the important part is clear.

OutOfMemoryError (not an exception) is thrown if there is not enough memory allocated for your JVM for objects created in your program. In your case, this can help increase the available heap space to more than 1 GB. If you think 1 GByte is enough, you might have a memory leak (which in Java most likely means that you have references to objects that you no longer need - maybe in some kind of cache?).

+4
source

Java reserves virtual memory for maximum heap size at startup. Since the program uses this memory, more main memory is allocated to it. On UNIX, this is displayed as resident memory. While Java programs can change to disk, the garbage collection works very poorly if part of the heap is swapped, and this can lead to blocking the whole system or rebooting it. If your program does not do this, you can be sure that it is completely in main memory.

Depending on what your application may require 1 GB, 10 GB or 100 GB or more. If you cannot increase the maximum amount of memory, you can use a memory profiler to help you find ways to reduce consumption. Start with VisualVM as it is built-in and free and does a decent job. If this is not enough, try a commercial profiler such as YourKit, for which you can get a free evaluation license (usually works long enough to fix your problem;)

The garbage collector automatically clears the memory as needed and can do this every few seconds or even more than once per second. If this can slow down your application, you should consider increasing your maximum size or reducing your consumption.

+3
source

The Java compiler does not allocate 1 GiB, as I think you think. Java dynamically allocates the necessary memory, and garbage collects it too, every time it allocates memory, it checks to see if it has enough space for this, and if not crashing. I guess somewhere in your code, because it would be almost impossible to write code that allocates many variables, you have an array or ArrayList that takes up all the memory. In the case of an array, you probably have a variable allocating its size, and you did some calculation for it, which is why it took up too much memory. In the case of ArrayList, I think you might have a loop in which there are too many iterations adding elements to it.

Check the code for the above errors and you should be good.

+1
source

What do you really mean in the "JVM Store memory on system"? JVM is, of course, the DEPENDED platform for the OS, but at the same time it is a set of frameworks. so I will try to explain the behavior of the JVM in the detailed steps:

1) Java code is compiled into bytecodes (understandable for the JVM);

2) The JVM processes these codes, and when the application starts, the JIT compiler calls the corresponding bytecode from the compiled source placed on the JVM. unlike previous applications (for example, WINapi), the platforms fully launched the HEX! application, so if you only needed to open a window with 1 window, the application stole your RAM until it was completely needed !;

3) The JVM finds the compiled bytecodes and when the corresponding event occurs, it only compiles the corresponding code! (THIS IS VERY IMPORTANT in the JVM), he does not. Also WinApi definitely does !;

4) it could be an Algorithmic error, and perhaps the application crashed due to some exceptional error or system failure (check this carefully!);

5) Of course! JVM depends on RAM memory, where else should it go further? -), therefore, he strongly recommended that you check the source code of the application first !. is jvm crashing? or does the application throw an exception ?, track it !;

6) Borh HEAP and STACK memory are part of COMPUTER MEMORY. for other purposes, distinguish memory cells in this way;

7) from memory is more like ERROR, not Exception !, so this is a platform problem, not an application. but NEVERTHESS, you can cause a memory error by creating the wrong algorithm, for example, an infinitive loop for creating objects, an infinitive increment of a value, etc;

Hope this helps even a little.

0
source

All Articles