誰かが私が見ているものがJava11の意図的で正しい動作なのか、それともある種のリークなのかを理解するのを手伝ってもらえますか?ばかげたシンプルなHelloWorldアプリを見てみましょう。
package com.example;
public class HelloWorld {
public static void main(String[] args) throws InterruptedException {
for( int i =0 ; i < 50; i++){
Thread.sleep(1000);
System.out.println("hello " + i);
}
}
}
唯一の興味深い部分は、jarの依存関係です。それはどんな瓶でもかまいませんが、問題をより壮観にするために、大きなものを使用しましょう-古いgwt-user jar、重さ30MB:
plugins {
id 'java'
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/com.google.gwt/gwt-user
compile group: 'com.google.gwt', name: 'gwt-user', version: '2.7.0'
}
アプリを実行し、jvisualvmを開き、ダンプを作成して、保持されている次のセットを探しますjava.util.zip.ZipFile$Source
。
クラスパスからのそのjar(実際には使用されていません)は1.5MBのヒープを占有します。GC中に消えることはなく、メモリが不足しても消えることはありません。これらのエントリはOutOfMemoryヒープダンプにも表示されます。
The entry is obviously kept by a map java.util.zip.ZipFile$Source.files
. From the source I can tell that this theoretically should be cleaned by a Common-Cleaner thread from InnocuousThreadGroup, but I don't see it happening.
I encountered this problem when migrating a small, lightweight Java app from JDK8 to JDK11. With low Xmx settings those jars use up significant portion of my heap as compared to JDK8.
So is it a bug or a feature?
This is deliberate.
The observation that memory use seem to increase is caused by moving from a native to pure java-based implementation[1] for zip/jar files in JDK 9. Mainly for stability purposes.
I'll note that the native implementation allocates similar and similarly sized data structures, but they were hidden out of sight from tools inspecting the java heap.
ただし、合計メモリフットプリントは多かれ少なかれ中立である必要がありますが、Javaヒープの使用量の増加に対応するために、Javaヒープサイズを増やす必要がある場合があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加