Firebase .on() listener causes Cordova iOS app crash

孤街醉人 提交于 2020-01-07 02:48:31

问题


I have made a blank, brand new Cordova app (-v 6.3.1), and built for iOS. The app does nothing except the following:

var ref = new Firebase('url-to-firebase-leaf-node-with-4000-children');
ref.on("child_added", function(child, prev) {
    console.log("here");
});

Deploy to iPhone. The app crashes, and Xcode cites the following:

WebThread (7): EXC_BAD_ACCESS (code=1, address=0xbbadbeef) inside of bmalloc::VMHeap::grow() .

If I do this rather:

var ref = new Firebase('url-to-firebase-leaf-node-with-100-children'); then the app doesn't crash.

This is clearly a memory problem, but how can it be resolved? With 1.5Mb of data being pulled down from 4,000 child nodes, I wouldn't have imagined this should be using up all available memory. Please avoid suggestions of not pulling all the data - the app needs all the data and works fine on Android.


回答1:


The native crash is pretty expressive. The application runs out of memory.

The Firebase SDK builds an in-memory mirror of the database using your subscriptions. Even if your child_added callback does not do anything with the child snapshots, this internal tree uses memory for all the data under the node.

Therefore you should consider using limits on your subscription, introducing pagination, or even restructuring the database if it fits your domain model.




回答2:


Before adding the child_added listener, ensure that you have cached all of the data (through the aforementioned pagination technique, or otherwise).



来源:https://stackoverflow.com/questions/39997522/firebase-on-listener-causes-cordova-ios-app-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!