couchbase / couchbase-lite-ios

Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps.
Apache License 2.0
1.63k stars 297 forks source link

Pull replication does not work because of memory leak #915

Closed roundandround closed 9 years ago

roundandround commented 9 years ago

Hi,

I'm trying to debug the issue with memory use while setting up the pull replication. The app crashes with out of memory error while syncing 16,000 documents with a few fields from CouchDB.

Here is what I see when I try to profile it with Instruments:

Graph    Category   # Persistent    Persistent Bytes
1   All Heap & Anonymous VM 4865    25.82 MB
0   All Heap Allocations    4816    611.45 KB
0   All Anonymous VM    49  25.22 MB    32  28.80 MB
0   VM: Performance tool data   47  24.97 MB
0   VM: SQLite page cache   2   256.00 KB
0   Malloc 4.00 KB  52  208.00 KB
0   CFString (immutable)    2184    123.25 KB
0   Malloc 272 Bytes    188 49.94 KB

VM: Performance tool data is growing all the time.

#   Address Category    Timestamp   Live    Size    Responsible Library Responsible Caller
0   0x10f05c000 VM: Performance tool data   00:02.125.818   • 544.00 KB   libBacktraceRecording.dylib 0x100785def
1   0x10f414000 VM: Performance tool data   00:02.682.811   • 544.00 KB   libBacktraceRecording.dylib 0x100785def
2   0x10f49c000 VM: Performance tool data   00:03.030.327   • 544.00 KB   libBacktraceRecording.dylib 0x100785def
3   0x10f524000 VM: Performance tool data   00:03.781.106   • 544.00 KB   libBacktraceRecording.dylib 0x100785def
4   0x10f5ac000 VM: Performance tool data   00:04.306.877   • 544.00 KB   libBacktraceRecording.dylib 0x100785def

I honestly don't know what should be my next steps. Do you have any pointers what this could be related to? Could not find any info on libBacktraceRecording.dylib

Have you seen this before? If not I can make an example that reproduces this problem.

CouchbaseLite/1.1.0 (iOS) Apache CouchDB 1.6.1

screen shot 2015-09-18 at 17 00 54

snej commented 9 years ago

Please use the leak tools in Instruments to detect what heap blocks are being leaked and what the backtraces are.

Also, what hardware are you running this on?

roundandround commented 9 years ago

Here is a small example that reproduces this problem: https://gist.github.com/roundandround/fc6a042102fcb1f3830e

You can download the full project from here: https://mega.nz/#!NsVUmKra!RSR9jtrdNpdMKPIYd64tWviFYjlCcg85Y71KPg-xJM0

The issue only happens when you run the code on the device using Xcode, it does not happen if you run the app standalone. So in a sense it's not an issue users would experience.

If you need the couchdb url, username and password, please send me an email to roundandroundy@outlook.com. Would prefer not to share it publicly.

Leak tools in Instruments does not detect this as leaks. The used memory just keeps increasing very fast.

Have tested it with following devices: iPhone 5S iOS 8.3 Affected iPod 5th gen iOS 8.3 Affected Could not reproduce it in simulator.

Xcode 6.4

roundandround commented 9 years ago

And here is the instruments trace. 39MB https://mega.nz/#!Zo9AgQhQ!V--GKj_Uc5LbSFAAkWZEfltMfZSwwYXxUHzP3Cxy1lY

roundandround commented 9 years ago

Not sure if it is relevant, but it happens while syncing tombstones. Number of objects trying to sync.

Deleted objects: 50000 Non deleted objects: 17193

snej commented 9 years ago

The issue only happens when you run the code on the device using Xcode, it does not happen if you run the app standalone

Are you sure you haven't enabled some of the memory diagnostics, like Zombies or Guard Malloc? That's what this sounds like to me.

roundandround commented 9 years ago

No memory management options enabled in diagnostics. Specifically no Zombie Objects and no Guard Malloc.

roundandround commented 9 years ago

These are default project settings, nothing custom.

snej commented 9 years ago

This doesn't look like a Couchbase Lite issue; rather it's something related to Xcode. libBacktraceRecording.dylib sounds like something that's capturing stack traces for performance measuring. As Instruments itself reports, nearly all of the memory usage is going to "VM: Performance tool data".

I would ask about this on Apple's dev forums, or the xcode-users mailing list on lists.apple.com.

zgramana commented 9 years ago

@roundandround sounds like you resolved your problem. If not, let us know otherwise we'll close this out in one week.