Couchbase lite iOS memory consumption

Hello

We are syncing on an iOS device (iPAD IOS 8.1) from a Database about 18K documents. Documents are synced ok, but when we launch a query on a a JavaScript View the app crashes with a memory error. Profiling the apps shows that more than 600MB of memory has been allocated by the JS garbage collector.

Any idea why this data is not freed ? any hint to garbage collect manually the JS heap ?

Hey @opic,

May you provide some logs from what you described and also code on your Map function may help too.

Sure , here is the map function.

function (doc) {
// Get Products AND Categories by levelIdFather
if (doc.shopCode && doc.levelIdFather) {
	if (doc.levelId) { // Category
		emit([doc.shopCode, doc.levelIdFather], {name : doc.name, levelId : doc.levelId});
	} else if (doc.sku) { // Product
		if (typeof doc.levelIdFather == "object") {
			for (var key in doc.levelIdFather) {
		        emit([doc.shopCode, key], {sku : doc.sku, name : doc.name, packaging : doc.packaging, priceOfUnit : doc.priceOfUnit, unitPrice : doc.unitPrice, base_url : doc.base_url, imageNumber : doc.imageNumber});
			}
		} else {
			emit([doc.shopCode, doc.levelIdFather], {sku : doc.sku, name : doc.name, packaging : doc.packaging, priceOfUnit : doc.priceOfUnit, unitPrice : doc.unitPrice, base_url : doc.base_url, imageNumber : doc.imageNumber});
		}
	}
}




/*try {
	emit(doc._id, doc._rev);
} catch (err) {
	log(err.message);
}*/

}

We can give you an access to a sync url where you will find a database with all the documents if you want to reproduce on iOS.

Also find below a sample document

{

“_id”: “product_42_3056440031637”,
"_rev": “2-64d43bb2dd4e8ae80e20253c894775ea”,
“shopCode”: “42”,
“sku”: “3056440031637”,
“levelIdFather”: “48196”,
“name”: “Biscuits chocolat noir Pépito”,
“packaging”: “les 2 paquets de 200 g”,
“priceOfUnit”: “4.05”,
“unitPrice”: “1.62”,
“base_url”: “http://XXXXX.fr/”,
“imageNumber”: “4077713”,
"~c8oAcl": “42”
}

How can we provide you logs ? how can we turn them on to be useful for you ?

Please file a bug report on Github. I don’t think logs will be needed.

I assume the rest of your app uses JS as well (is this PhoneGap?) How do you know that it’s the map function allocating all the memory and not the rest of the app?

We did not reproduce this problem. And yes it was on PhoneGap. Anyway, thank for your help.

Hello, I reopen the topic as we have a now a reproducible case for crashing CBL iOS with a 13K document database.

This app is a standard PhoneGap app using the CBL plugin 1.04; We made it the simplest possible to be sure no other component was interfering with memory consumption.

You can download it from here :

http://d2lm6861ur7e1f.cloudfront.net/webrepository/DebugMemory.zip

This a a cordova /phone app you can use to build with Phonegap Build or locally. The app will connect to a cloud based CouchDB server .

You can use the “Sync” button to trigger the sync downloading all the database to the mobile. Then you can use the “View” button to launch a query on the database using the javascript view. The view will start indexing and the app crashes about 10 to 15 secs later.

This has been tested on an iPad mini iOS8.1 and an iPhone 4 iOS 8.1

Thank You
Olivier

Thanks for isolating a test case! But this forum is not an issue tracker. Please file a bug report here.

Also, if you could include the crash log in your report (including the backtrace) so we can see the details without having to first build/run the app, that would be super useful.

Sorry : ) The bug has been now filed correctly.
Thx
Olivier

I write a phonegap/Ionic couchbase lite 1.0.4 app. I want to sync 60.000 Documents and later more. When i start the sync on a iPhone Device ( 6Plus) the memory increases up to 300MB after 2 min and the App crashes. In the Console the Message is Received memory warning. What can i do?

It shouldn’t be using that much memory. Which version of CBL is this? And do your docs have attachments?

Hey,

We’re in the middle of revamping the Apache Cordova example, and it may be of use to you guys:

It is with Ionic, but more importantly, you will be able to see the RESTful calls made to the plugin. You may be able to use a bunch of the source code to help troubleshoot your issues.

Best,

This could be related to this issue #701. The fix was included into v1.1 which should be released soon.

Thank you for your reply. I have updated the Device from IOS 8.2 to 8.3 the memory is not more the Problem. Now the CPU increases up to 140%. i have no attachments and i have couchbase lite phonegap v.1.0.4
This is my Sync Scriptsync.js.zip (3.4 KB)