1
1
package io .fullstack .firestack .database ;
2
2
3
- import java .util .HashSet ;
4
3
import java .util .List ;
5
4
import android .util .Log ;
6
5
import java .util .ListIterator ;
7
- import java .util .Set ;
8
6
9
7
import com .facebook .react .bridge .Callback ;
10
8
import com .facebook .react .bridge .Arguments ;
@@ -29,7 +27,6 @@ public class FirestackDatabaseReference {
29
27
private String mModifiersString ;
30
28
private ChildEventListener mEventListener ;
31
29
private ValueEventListener mValueListener ;
32
- private Set <ValueEventListener > mOnceValueListeners = new HashSet <>();
33
30
private ReactContext mReactContext ;
34
31
35
32
public FirestackDatabaseReference (final ReactContext context ,
@@ -104,7 +101,6 @@ public void addOnceValueEventListener(final Callback callback) {
104
101
@ Override
105
102
public void onDataChange (DataSnapshot dataSnapshot ) {
106
103
WritableMap data = Utils .dataSnapshotToMap ("value" , mPath , mModifiersString , dataSnapshot );
107
- mOnceValueListeners .remove (this );
108
104
callback .invoke (null , data );
109
105
}
110
106
@@ -114,22 +110,17 @@ public void onCancelled(DatabaseError error) {
114
110
err .putInt ("errorCode" , error .getCode ());
115
111
err .putString ("errorDetails" , error .getDetails ());
116
112
err .putString ("description" , error .getMessage ());
117
- mOnceValueListeners .remove (this );
118
113
callback .invoke (err );
119
114
}
120
115
};
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 );
125
116
mQuery .addListenerForSingleValueEvent (onceValueEventListener );
126
117
Log .d (TAG , "Added OnceValueEventListener for path: " + mPath + " with modifiers " + mModifiersString );
127
118
}
128
119
129
120
public void cleanup () {
130
121
Log .d (TAG , "cleaning up database reference " + this );
131
122
this .removeChildEventListener ();
132
- this .removeValueEventListeners ();
123
+ this .removeValueEventListener ();
133
124
}
134
125
135
126
private void removeChildEventListener () {
@@ -139,15 +130,11 @@ private void removeChildEventListener() {
139
130
}
140
131
}
141
132
142
- private void removeValueEventListeners () {
133
+ private void removeValueEventListener () {
143
134
if (mValueListener != null ) {
144
135
mQuery .removeEventListener (mValueListener );
145
136
mValueListener = null ;
146
137
}
147
- for (ValueEventListener onceValueListener : mOnceValueListeners ) {
148
- mQuery .removeEventListener (onceValueListener );
149
- }
150
- mOnceValueListeners = new HashSet <>();
151
138
}
152
139
153
140
private void handleDatabaseEvent (final String name , final DataSnapshot dataSnapshot ) {
0 commit comments