Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unload / Release / Remove React Native View from runtime

I am creating a App that uses React Native in some part, but not all.

I have an instance of RCTRootView

Setting it to nil and removing it from the superview doesn't seem to release it.

The CPU and RAM stays high, so it seems the React app stills executing on the threads.

How can I stop it?

Thanks :)

like image 765
Gaston Morixe Avatar asked Dec 08 '15 23:12

Gaston Morixe


People also ask

Does console log affect performance React Native?

yes. More code means a longer execution time. Not only will it take unnecessary CPU "power", console. log is also synchronous so it will make your application slower (even by a few nanoseconds).

Why is React Native so slow?

Memory leakage, a React Native performance issue, may occur due to unnecessary processes that run in the background in an Android app. Try using scrolling lists like SectionList, FlatList, or VirtualList, instead of ListView.

Does console log slow down React Native?

log statements. Though console. log( ) statements are important to debug your react native app but these statements in huge numbers can cause performance lag in your react native app. The reason being that these pieces of code are synchronous so they might slow down your app.

How do I speed up React Native?

Some improvements that can be applied to optimize images in a React Native app are: Using PNG format instead of JPG format. Using smaller-resolution images. Using WEBP format for images – this can help reduce the images' binary size on iOS and Android by nearly a third of the original size!


2 Answers

RCTBridge * bridge
[bridge invalidate];
bridge = nil;

invalidate and nil will clear all modules from jsbundle and it clears RCTRootView instances from memory . Note bridge is object of RCTBridge.

like image 147
Shashi3456643 Avatar answered Sep 28 '22 05:09

Shashi3456643


You have to create your own RTCBridge separately and release it ( = nil), not only the view.

like image 30
Gaston Morixe Avatar answered Sep 28 '22 05:09

Gaston Morixe