Skip to content

Commit 97b767e

Browse files
clinuxrulzjbgi
authored andcommitted
Hard memo memory reduction (#258)
* hard memo memory reduction. Dereferences the computation allowing it to become garbage collected once the value has been memorised. * removed initialized
1 parent 6b3905d commit 97b767e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

core/src/main/java/fj/P1.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,18 @@ public static <A> P1<A> memo(F0<A> f) {
268268
}
269269

270270
static class Memo<A> extends P1<A> {
271-
private final P1<A> self;
272-
private volatile boolean initialized;
271+
private volatile P1<A> self;
273272
private A value;
274273

275274
Memo(P1<A> self) { this.self = self; }
276275

277276
@Override public final A _1() {
278-
if (!initialized) {
277+
if (self != null) {
279278
synchronized (this) {
280-
if (!initialized) {
279+
if (self != null) {
281280
A a = self._1();
282281
value = a;
283-
initialized = true;
282+
self = null;
284283
return a;
285284
}
286285
}

0 commit comments

Comments
 (0)