4 Temmuz 2022 Pazartesi

SoftReference Nesnesi

Giriş
Açıklaması şöyle. Yani WeakReference'tan biraz daha katıdır ve OutOfMemory oluncaya kadar belleği bırakmamaya çalışırlar
Soft References behave very similarly to the weak ones with the difference that they are not that eager to let the object to be collected. They behave like strong references until the memory runs out. If the JVM starts reaching its upper ram limits it will collect the soft referenced objects, so in theory they should never cause an OutOfMemory error. 
Örnek
Şöyle yaparız
List<SoftReference<Object>> lst = new ArrayList<>();
while (true) {
  lst.add(new SoftReference<>(Files.readAllBytes(Paths.get("huge.txt"))));
}

Hiç yorum yok:

Yorum Gönder