Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android]fix memory leak in Android #35889

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ public synchronized void removeRootView(int rootViewTag) {
mRootTags.delete(rootViewTag);
}

/**
* Return root view num
*
* @return The num of root view
*/
public synchronized int getRootViewNum() {
return mRootTags.size();
}

/**
* Returns true on success, false on failure. If successful, after calling, output buffer will be
* {x, y, width, height}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ public void removeRootView(int rootViewTag) {
mOperationsQueue.enqueueRemoveRootView(rootViewTag);
}

/**
* Return root view num
*
* @return The num of root view
*/
private int getRootViewNum() {
return mOperationsQueue.getNativeViewHierarchyManager().getRootViewNum();
}

/** Unregisters a root node with a given tag from the shadow node registry */
public void removeRootShadowNode(int rootViewTag) {
synchronized (uiImplementationThreadLock) {
Expand Down Expand Up @@ -599,6 +608,12 @@ public void measureLayoutRelativeToParent(

/** Invoked at the end of the transaction to commit any updates to the node hierarchy. */
public void dispatchViewUpdates(int batchId) {
if (getRootViewNum() <= 0) {
// If there are no RootViews registered, there will be no View updates to dispatch.
// This is a hack to prevent this from being called when Fabric is used everywhere.
// This should no longer be necessary in Bridgeless Mode.
return;
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIImplementation.dispatchViewUpdates")
.arg("batchId", batchId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public interface CustomEventNamesResolver {
private volatile int mViewManagerConstantsCacheSize;

private int mBatchId = 0;
private int mNumRootViews = 0;

public UIManagerModule(
ReactApplicationContext reactContext,
Expand Down Expand Up @@ -403,7 +402,6 @@ public <T extends View> int addRootView(
-1);

mUIImplementation.registerRootView(rootView, tag, themedRootContext);
mNumRootViews++;
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
return tag;
}
Expand All @@ -427,7 +425,6 @@ public void stopSurface(final int surfaceId) {
@ReactMethod
public void removeRootView(int rootViewTag) {
mUIImplementation.removeRootView(rootViewTag);
mNumRootViews--;
}

public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) {
Expand Down Expand Up @@ -768,12 +765,7 @@ public void onBatchComplete() {
listener.willDispatchViewUpdates(this);
}
try {
// If there are no RootViews registered, there will be no View updates to dispatch.
// This is a hack to prevent this from being called when Fabric is used everywhere.
// This should no longer be necessary in Bridgeless Mode.
if (mNumRootViews > 0) {
mUIImplementation.dispatchViewUpdates(batchId);
}
mUIImplementation.dispatchViewUpdates(batchId);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
Expand Down