Reputation: 413
I use FCM to handle notifications in my iOS app. All works fine, but I have encountered problems when I have to handle about 300 - 400 topic subscriptions at the same time. When i start my app, this function is called about 400 times:
FIRMessaging.messaging().subscribeToTopic("/topics/\(nameoftopic)")
But after it has been called about 300 times, the app crashes, without messages from debugger. I think the crash is related to memory leaks, but i am not sure.
Can anyone help me? Thank you!
UPDATE
After using Instruments's allocation tool with the app running on the simulator, i've found something interesting.
Note: If I use the app in the simulator, it does not crash.
Here is the situation of my app before calling the "subscribe 400 topics" function:
And here is the situation of the app after calling the "subscribe 400 topics" function:
As you can see, there is a lot of memory using, for example the Malloc 3,00 kib record in the image, retains about 424 MiB!
Is there a way to solve this problem? Thank you!
UPDATE:
The subscriptions to the topics are fired by a javascript call into a WKWebView inside my app. In particular:
I've tried to comment the native iOS function (which subscribes to the topic) called by the javascript function, but the app keeps crashing.
So, I think the problem is concerned to the javascript bridging (who calls a native function from a javascript function called by the webview) which is called 400 times, and not directly to the subscription to multiple topics.
EDIT:
Here is the crash log:
Incident Identifier: 431E0DD6-8AEC-4614-B417-3320FB08C2B4
CrashReporter Key: d651543acfe23fc7feac21ffef17bfcbc8d222b3
Hardware Model: iPad2,2
OS Version: iPhone OS 8.1.3 (12B466)
Kernel Version: Darwin Kernel Version 14.0.0: Mon Jan 12 21:30:11 PST 2015; root:xnu-2783.3.26~3/RELEASE_ARM_S5L8940X
Date: 2016-07-21 10:18:37 +0200
Time since snapshot: 68 ms
Free pages: 1092
Active pages: 3736
Inactive pages: 1929
Speculative pages: 147
Throttled pages: 100888
Purgeable pages: 0
Wired pages: 20866
File-backed pages: 5413
Anonymous pages: 399
Compressions: 12087
Decompressions: 4011
Compressor Size: 63
Uncompressed Pages in Compressor: 0
Page Size: 4096
Largest process: TestApp
Processes
Name | <UUID> | CPU Time| rpages| purgeable| recent_max| lifetime_max| fds | [reason] | (state)
swcd <e22b9809b0b83a3d822cdd499e630b44> 0.089 153 0 - 529 50 [vm-pageshortage] (daemon)
nsurlsessiond <d04dc25e93283de3b7ee8db12bd33953> 0.794 336 0 - 1543 50 [vm-pageshortage] (daemon)
debugserver <ef1b24f73ea43149b0666ea20e5f7dda> 1.770 154 0 +8 679 50 [vm-pageshortage] (daemon)
kbd <008376fef2c13eab9d7b6cd71eacf1d7> 3.369 553 0 - 2063 50 [vm-pageshortage] (daemon)
tccd <1c3b7672d405345a9599a9165b4e9672> 3.334 197 0 - 854 50 (daemon)
lsd <18a22fa1c3ba3aa0871ad1843aa4c847> 2.169 269 0 - 1225 50 (daemon)
com.apple.WebKit <509457e569a934bc8289a7a1b8943347> 3.089 2453 0 +55 3493 50 (frontmost)
com.apple.WebKit <509457e569a934bc8289a7a1b8943347> 7.421 18667 0 - 17412 50 (frontmost)
TestApp <de60e10c4dca3921ad7cc901b68dc71f> 11.944 53345 0 - 53845 50 (frontmost) (resume)
ptpd <899195f7d556391998a2cacb7371751c> 1.522 801 0 - 1715 50 (daemon)
BTServer <24daf6f44d893f6daf5a680c92b63fc7> 2.992 350 0 - 1482 50 (daemon)
lockdownd <2da4a7e0dd1a35b9ae05f52e8d5aad3a> 16.308 215 0 - 1019 50 (daemon)
discoveryd <7b61a3893f0f3f2ca2227304d7fc0a05> 55.199 661 0 - 1942 400 (daemon)
wifid <b9f927d2166a35ddbcddfc792aa06a88> 46.416 422 0 - 1352 50 (daemon)
locationd <0017f8e9b9803dc7b82ab6c21acb6487> 563.557 1491 0 - 4018 50 (daemon)
imagent <2db1206e12ef30fe833d30a6857badf9> 10.430 486 0 - 1964 50 (daemon)
identityservices <235ad60b31753ba39ca43729cbac31fd> 14.170 473 0 - 2232 50 (daemon)
syslogd <21614327a5913635bf8bc2272aab94ae> 47.307 197 0 - 1426 50 (daemon)
iaptransportd <8ee55cf028c0311b939e0113712a1344> 7.143 301 0 - 803 50 (daemon)
mediaserverd <951ab0492a0c3a119805c38697cf67e7> 101.623 921 0 - 2603 50 (daemon)
cfprefsd <77e3ddae064b3007a4f5d13522c29767> 57.303 313 0 - 707 50 (daemon)
powerd <496f3f6fd0173e5d8ca1dfceadc76dd1> 24.261 217 0 - 460 50 (daemon)
networkd <385c01062c27379d883f244a17aaf235> 86.147 672 0 - 1723 50 (daemon)
apsd <8da1c66348543d4ebd72e810fc2f36e0> 38.871 576 0 - 1737 100 (daemon)
dataaccessd <a7a7f65633c03d5985c23a80b0db4c97> 10.382 596 0 - 2042 50 (daemon)
iapd <03badd6a166c3daf934c29ce1d86e128> 9.314 435 0 - 1542 50 (daemon)
CommCenterMobile <0fd2ae4f78ae3df3830cdd46aa29b06c> 0.732 336 0 - 1304 50 (daemon)
searchd <9d6bf30189a23d6d959aaf2c08c19607> 1.100 724 0 - 2523 50 (daemon)
mediaremoted <5a7484513dca313997af39582eb8cc8f> 0.720 216 0 - 1050 50 (daemon)
syncdefaultsd <b377e47d27323a97b4a00d85e6af8530> 0.245 297 0 - 1068 50 (daemon)
securityd <9f54dbee58003edc82e0648fad2f75f8> 3.328 575 0 - 1412 50 (daemon)
SpringBoard <a09599dad0b73d488762bbf4df172b0a> 649.777 5161 0 - 13265 50
backboardd <119c485cefcd3127a318d4fc1636dbeb> 2110.390 7113 0 - 4717 50 (daemon)
UserEventAgent <736bfc71654a3e1284af9976c16a00a5> 200.859 740 0 - 2351 100 (daemon)
configd <8df7332b99003995862643fdbb1c8b00> 31.570 397 0 - 1203 50 (daemon)
fseventsd <a366dd315e273afc96084abc8f6f1c3e> 14.679 318 0 - 837 50 (daemon)
fairplayd.A1 <f3eaf6eefeea37378292c8cf9eaab5ac> 20.154 144 0 - 1469 50 (daemon)
assertiond <b5cb3ee93d6a32b1a08fbf075ae23191> 18.089 267 0 - 936 50 (daemon)
distnoted <42234e3ec6563c7dac4d510e301f6946> 3.826 157 0 - 263 50 (daemon)
discoveryd_helpe <09b3407bfeff330299a6a84dd8673ac3> 0.419 125 0 - 567 50 (daemon)
filecoordination <4450909aaf823fd1a96a4c94813c9da0> 2.506 212 0 - 784 50 (daemon)
aggregated <6747e33da38f39688022fe05295a7fad> 814.695 999 0 - 1990 50 (daemon)
DTMobileIS <96811bdfb87837499227af222f3d8471> 10.993 463 0 - 1921 50 (daemon)
ubd <44b27d08a6823a859e0ec08131f20be9> 0.194 181 0 - 714 50 (daemon)
accountsd <d18f8d0e475d3dcbac17a98abcdf70e9> 1.345 379 0 - 1005 50 (daemon)
CommCenterClassi <7cdb180802b53bc9bce7cafb749d09ca> 110.886 585 0 - 2352 50 (daemon)
notifyd <1166f790e0e73573afb6b0ff4708366c> 44.864 240 0 - 293 50 (daemon)
xpcproxy <4b3cd1e859d031e4b855c1c48aa1344f> 0.004 16 0 - 52 50 (daemon)
**End**
Upvotes: 1
Views: 392
Reputation: 91
Are you assigning a strongly referenced variable in one class to another variable in another class that isn't prefixed with "weak" or "unowned"? Doing so creates a strong reference cycle that will eat away at ARC's working memory.
If you are concerned about memory leak, use the Allocations tool, accessed in the top menu of Xcode by selecting "Instruments." Alternatively you can access instruments with Cmd+I.
Upvotes: 0
Reputation: 7494
Are you subscribing every single time? If yes, then this should not be happening. The subscriptions should only happen the first time a user starts the app and beyond that only when a user subscribes to a topic (and even then only that specific action should be taken).
If your actions are taking time, delegate this to a background thread.
Upvotes: 0