Linked Questions
32 questions linked to/from What's the difference between SoftReference and WeakReference in Java?
30
votes
3
answers
5k
views
Can someone explain the difference between Strong, Soft, Weak and Phantom references and the usage of it? [duplicate]
I have been trying to understand the difference between different references but the theory does not provoke any ideas for me to visualize the same.
Could anyone please explain in brief the different ...
597
votes
33
answers
2.5m
views
How to deal with "java.lang.OutOfMemoryError: Java heap space" error?
I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryError: Java heap space error because I am not being conservative on ...
172
votes
10
answers
63k
views
When would you use a WeakHashMap or a WeakReference?
The use of weak references is something that I've never seen an implementation of so I'm trying to figure out what the use case for them is and how the implementation would work. When have you needed ...
193
votes
4
answers
110k
views
How to use WeakReference in Java and Android development?
I have been a Java developer for 2 years.
But I have never written a WeakReference in my code. How to use WeakReference to make my application more efficient, especially the Android application?
87
votes
5
answers
54k
views
Extension fields in Kotlin
It's easy to write extension methods in Kotlin:
class A { }
class B {
fun A.newFunction() { ... }
}
But is there some way to create extension variable? Like:
class B {
var A.someCounter: Int ...
21
votes
10
answers
18k
views
How to cause soft references to be cleared in Java?
I have a cache which has soft references to the cached objects. I am trying to write a functional test for behavior of classes which use the cache specifically for what happens when the cached objects ...
8
votes
14
answers
1k
views
In java, how can we destruct an instance of a class from a method within the class
I approached it similar to the case of deleting any usual object, ie, simply making the reference null and letting the Garbage Collector do its job.
However for equating to null within a class, the ...
11
votes
5
answers
8k
views
Howto delete all object pointer in java
is there an elegant way in Java to set all existing object-pointers to null?
I want an object to be deleted, but it is registered in several places an Event Listener.
21
votes
7
answers
5k
views
Long lived Java WeakReferences
I am currently trying to diagnose a slow memory leak in my application. The facts I have so far are as follows.
I have a heap dump from a 4 day run of the application.
This heap dump contains ~800 ...
8
votes
4
answers
6k
views
When to use Weak and Phantom references in Java
I read many articles, but I don't understand - where do I need to use Weak and Phantom references in practice? Soft references - is a good choice for cache, as I understand. But weak and phantom, I ...
1
vote
3
answers
4k
views
Force removing object from memory
How can i delete object even it has references(c# or Java)?
For example:
void Main()
{
var f = new Foo();
var person = f.GetPerson();
}
public class Foo
{
private object _person;
...
8
votes
2
answers
1k
views
What are the "practical consequences" of using soft references?
Per the documentation for Guava's MapMaker.softValues():
Warning: in most circumstances it is better to set a per-cache maximum size instead of using soft references. You should only use this method ...
3
votes
2
answers
1k
views
What is a softly reachable object?
I am trying to study the meaning of a soft reference via this 'Soft References in Java' article:
https://www.baeldung.com/java-soft-references
My problem in understanding this article is that it ...
4
votes
2
answers
2k
views
Is WeakHashMap ever-growing, or does it clear out the garbage keys?
I am trying to use WeakHashMap as a concurrent Set of weak references.
this.subscribers =
Collections.synchronizedSet(
Collections.newSetFromMap(
...
1
vote
2
answers
628
views
Is GC smart enough to remove objects that are referenced but no longer used?
Let's say I have an object called "master" which owns 100 objects called "slave0" through "slave99" respectively. (This is not an array. I have 100 fields in my "master" class called salve0 to slave99 ...