Browse Source

[Android] Fix resource leak when JitsiMeetView is destroyed

In iOS this is automagically done in the view destructor, bunt we don't have
that luxury in Java we have to do it manually.

The new disponse() method MUST be called when the Activity holding the view is
going to be destroyed, typically in the onDestroy() handler.
j8
Saúl Ibarra Corretgé 8 years ago
parent
commit
bfa5f4c953

+ 9
- 0
android/README.md View File

56
     protected void onDestroy() {
56
     protected void onDestroy() {
57
         super.onDestroy();
57
         super.onDestroy();
58
 
58
 
59
+        view.dispose();
60
+        view = null;
61
+
59
         JitsiMeetView.onHostDestroy(this);
62
         JitsiMeetView.onHostDestroy(this);
60
     }
63
     }
61
 
64
 
102
 The `JitsiMeetView` class is the core of Jitsi Meet SDK. It's designed to
105
 The `JitsiMeetView` class is the core of Jitsi Meet SDK. It's designed to
103
 display a Jitsi Meet conference (or a welcome page).
106
 display a Jitsi Meet conference (or a welcome page).
104
 
107
 
108
+#### dispose()
109
+
110
+Releases all resources associated with this view. This method MUST be called
111
+when the Activity holding this view is going to be destroyed, usually in the
112
+`onDestroy()` method.
113
+
105
 #### getListener()
114
 #### getListener()
106
 
115
 
107
 Returns the `JitsiMeetViewListener` instance attached to the view.
116
 Returns the `JitsiMeetViewListener` instance attached to the view.

+ 5
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java View File

154
     protected void onDestroy() {
154
     protected void onDestroy() {
155
         super.onDestroy();
155
         super.onDestroy();
156
 
156
 
157
+        if (view != null) {
158
+            view.dispose();
159
+            view = null;
160
+        }
161
+
157
         JitsiMeetView.onHostDestroy(this);
162
         JitsiMeetView.onHostDestroy(this);
158
     }
163
     }
159
 
164
 

+ 16
- 4
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java View File

199
         views.add(this);
199
         views.add(this);
200
     }
200
     }
201
 
201
 
202
+    /**
203
+     * Releases the React resources (specifically the {@link ReactRootView})
204
+     * associated with this view.
205
+     *
206
+     * This method MUST be called when the Activity holding this view is destroyed, typically in the
207
+     * {@code onDestroy} method.
208
+     */
209
+    public void dispose() {
210
+        if (reactRootView != null) {
211
+            removeView(reactRootView);
212
+            reactRootView.unmountReactApplication();
213
+            reactRootView = null;
214
+        }
215
+    }
216
+
202
     /**
217
     /**
203
      * Gets the {@link JitsiMeetViewListener} set on this {@code JitsiMeetView}.
218
      * Gets the {@link JitsiMeetViewListener} set on this {@code JitsiMeetView}.
204
      *
219
      *
257
 
272
 
258
         // TODO: ReactRootView#setAppProperties is only available on React
273
         // TODO: ReactRootView#setAppProperties is only available on React
259
         // Native 0.45, so destroy the current root view and create a new one.
274
         // Native 0.45, so destroy the current root view and create a new one.
260
-        if (reactRootView != null) {
261
-            removeView(reactRootView);
262
-            reactRootView = null;
263
-        }
275
+        dispose();
264
 
276
 
265
         reactRootView = new ReactRootView(getContext());
277
         reactRootView = new ReactRootView(getContext());
266
         reactRootView.startReactApplication(reactInstanceManager, "App", props);
278
         reactRootView.startReactApplication(reactInstanceManager, "App", props);

Loading…
Cancel
Save