Skip to content

Commit 5a95fb3

Browse files
committed
Remove unnecessary storage of once event listeners
1 parent ec9f488 commit 5a95fb3

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

android/src/main/java/io/fullstack/firestack/database/FirestackDatabaseReference.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package io.fullstack.firestack.database;
22

3-
import java.util.HashSet;
43
import java.util.List;
54
import android.util.Log;
65
import java.util.ListIterator;
7-
import java.util.Set;
86

97
import com.facebook.react.bridge.Callback;
108
import com.facebook.react.bridge.Arguments;
@@ -29,7 +27,6 @@ public class FirestackDatabaseReference {
2927
private String mModifiersString;
3028
private ChildEventListener mEventListener;
3129
private ValueEventListener mValueListener;
32-
private Set<ValueEventListener> mOnceValueListeners = new HashSet<>();
3330
private ReactContext mReactContext;
3431

3532
public FirestackDatabaseReference(final ReactContext context,
@@ -104,7 +101,6 @@ public void addOnceValueEventListener(final Callback callback) {
104101
@Override
105102
public void onDataChange(DataSnapshot dataSnapshot) {
106103
WritableMap data = Utils.dataSnapshotToMap("value", mPath, mModifiersString, dataSnapshot);
107-
mOnceValueListeners.remove(this);
108104
callback.invoke(null, data);
109105
}
110106

@@ -114,22 +110,17 @@ public void onCancelled(DatabaseError error) {
114110
err.putInt("errorCode", error.getCode());
115111
err.putString("errorDetails", error.getDetails());
116112
err.putString("description", error.getMessage());
117-
mOnceValueListeners.remove(this);
118113
callback.invoke(err);
119114
}
120115
};
121-
122-
//TODO ? Is it really necessary to track this type of event listener as they are automatically
123-
//removed by Firebase when the event is fired. Very slim chance of memory leak.
124-
mOnceValueListeners.add(onceValueEventListener);
125116
mQuery.addListenerForSingleValueEvent(onceValueEventListener);
126117
Log.d(TAG, "Added OnceValueEventListener for path: " + mPath + " with modifiers " + mModifiersString);
127118
}
128119

129120
public void cleanup() {
130121
Log.d(TAG, "cleaning up database reference " + this);
131122
this.removeChildEventListener();
132-
this.removeValueEventListeners();
123+
this.removeValueEventListener();
133124
}
134125

135126
private void removeChildEventListener() {
@@ -139,15 +130,11 @@ private void removeChildEventListener() {
139130
}
140131
}
141132

142-
private void removeValueEventListeners() {
133+
private void removeValueEventListener() {
143134
if (mValueListener != null) {
144135
mQuery.removeEventListener(mValueListener);
145136
mValueListener = null;
146137
}
147-
for (ValueEventListener onceValueListener : mOnceValueListeners) {
148-
mQuery.removeEventListener(onceValueListener);
149-
}
150-
mOnceValueListeners = new HashSet<>();
151138
}
152139

153140
private void handleDatabaseEvent(final String name, final DataSnapshot dataSnapshot) {

0 commit comments

Comments
 (0)