简体   繁体   中英

Firebase .on() listener causes Cordova iOS app crash

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.

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.

在添加child_added侦听器之前,请确保已缓存了所有数据(通过上述分页技术或其他方式)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM