Skip to content
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

Outofmemoryerror occurred #1392

Closed
dwj1979 opened this issue Nov 3, 2020 · 17 comments
Closed

Outofmemoryerror occurred #1392

dwj1979 opened this issue Nov 3, 2020 · 17 comments

Comments

@dwj1979
Copy link

dwj1979 commented Nov 3, 2020

I am using oshi to obtain the utilization rate of system resources. However, the following OutOfMemoryError has occurred frequently in the system recently.

java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: GC overhead limit exceeded

By analyzing dumplog (using jhat java_pid8732.hprof ), it is found that there are a large number of oshi's instances, as follows:

Instance Counts for All Classes (excluding platform)
811603 instances of class oshi.util.platform.windows.PerfCounterQueryHandler

my code be excuted every second in the timer job:
List diskStores = hal.getDiskStores();
for (HWDiskStore disk : diskStores) {
List partitions = disk.getPartitions();
if (partitions == null) {
continue;
}
//获取系统盘和云雀安装盘的磁盘信息
for (HWPartition part : partitions) {
System.out.println(part.getMountPoint())
}
}

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

Which version of OSHI are you using?

This could be the bug reported in #1244 and fixed in #1245 in versions 4.8.1 (for 4.X branch) and 5.1.1.

@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

thank you for answer。
version: 5.1.0

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

Upgrading to the latest version should solve the problem. :)

@dbwiddis dbwiddis closed this as completed Nov 3, 2020
@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

I have upgraded to the latest version, but the memery consumption has been increasing。

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

It's normal for heap to increase with a high heap limit, as objects are created and destroyed, but garbage collection will kick in eventually.

@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

i use the following code, jvm args: -Xms200m -Xmx200m, although memery consumption has reached 600m, GC has not been recycled。
public static void main(String[] args) {
SystemInfo info = new SystemInfo();
List disks = info.getHardware().getDiskStores();
while (true) {
for (HWDiskStore disk : disks) {
disk.updateAttributes();
}
}
}

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

The -Xmx value is just the heap memory. From Oracle docs:

Java objects reside in an area called the heap. The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.

Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.

600m total memory for a 200m heap limit seems reasonable. This SO post indicates a 128m limit and 550m peak.

Are you still getting OutOfMemory errors?

@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

but the memery consumption has been increasing。now has reached 1.2G

@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

please try the code:

public static void main(String[] args) {
SystemInfo info = new SystemInfo();
List disks = info.getHardware().getDiskStores();
while (true) {
for (HWDiskStore disk : disks) {
disk.updateAttributes();
}
}
}

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

Are you still getting OutOfMemory errors?

@dbwiddis dbwiddis reopened this Nov 3, 2020
@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

have not throw OutOfMemoryErrors

@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

but the memery consumption has been increasing。

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

I can run that code with no problem. I use 2G heap and my memory peaks out at about 1.5 GiB. How are you measuring memory usage?

@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

using taskManager

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

The JVM doesn't have a memory limit, and will use as much OS memory as is conveniently available for a variety of things to improve performance. You're seeing JVM memory being used, not your heap memory which is limited by Xmx.

If you run your program long enough, you'll see it level out. If you start up another program that needs memory, you might see it decrease.

@dbwiddis
Copy link
Member

dbwiddis commented Nov 3, 2020

See this article for example.

@dbwiddis dbwiddis closed this as completed Nov 3, 2020
@dwj1979
Copy link
Author

dwj1979 commented Nov 3, 2020

thank you answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants