Why does my Unity ios app's Documents and Data keep increasing? - ios

I created my first app back in July. It came out to be 55mb. I have recently noticed that the Documents and Data section for my app is 150mb, nearly 3 times the app size. Doing more tests I have realized that each time I play the game it increases by 1mb. It is now at 170mb.
I am using Unity 5.6.1p4 and Google Admob.
My app does not download any update files to run the game so that isn't the issue.
I have a couple of guesses but none seem very likely:
1) My game is only about half as optimized as it should be. I still use a lot of instantiate and destroy. An other post said that the memory issue is due to Apple's inability to garbage collect. That is a possibility but I cannot understand why the data from instantiate/destroy would be cached. I also find it hard to believe no one else has had that issue.
2) When the game first starts, it automatically loads a banner ad and a video ad so that there is no delay when the user first requests a reward video. Some people have said that Google Admob caches ads so there is less data usage. That seems like it would cause some increase in file size but 170mb is too much data to be cached. Again I find it hard to believe no one would have complained to Google about this before.
Any help would be greatly appreciated. I cannot figure out what would be causing it. If you are interested in seeing the problem first hand, the App Store link is https://appsto.re/us/nco9gb.i

Ok, here is my findings: This is either an issue for older phones, or iOS 10.x.
However, I do not know which. I am able to test iOS 10 on older phones (5, 5s and ipad 1). I am not able to find any newer device still running iOS 10. This memory glitch does not seem to happen on iOS 11. I was able to test it on 3x iphone 6s, 2x iphone 7 all running iOS 11.It is not as clear as I would like it to be but iOS 11 does not appear to have the memory issue. As much as I would like to find the cause and fix it, I think the majority of people should be safe because they update.

Related

ridiculously high storage usage in iPhone 6+

I'm working (helping out) on an iOS app. On most devices the app's stabilized storage use is within 60-80MB. The same app (and same revision) on the iPhone 6+ starts using Gigabytes of data within minutes ... to the point of filling up the storage and I can't even run the app from XCode anymore. I've only been able to get it on the iPhone 6 once, but it's a regular occurrence on the 6+. I've also tried on a range of other devices from 5th gen iPod touch to the iPhone 5 and no other device goes over the 80MB.
The only portion of code that uses a significant amount of storage is the image caching, which caches the (static) images downloaded from the server keyed on the image id. Then again this code is (or seems to be) working fine on other devices. It is also a portion of the codebase that hasn't changed in a while.
Can anyone think of a reason why this issue is only seen on the iPhone6+ (and to a much lower extent the iPhone6)?
This isn't a solution, since it's impossible to know what's happening, but you should look at the following:
Is this reproducible on the simulator? (file system is easier to view)
Does the storage get freed when the app is deleted?
Can you see the data in the device organiser in xcode (they keep moving it, but somewhere you can plug in the device, see the app, and then see the file sandbox for that app)
What data is it? This should give you a clue as to its origin
is there a set of actions in the app that kick off the problem?
If this works, you should get a clue as to the offending code. Then, update your question, unless the solution is obvious!
The problem was that malloc stack logging was enabled and not set to compact. It logged every single allocation made by the app and it was the log file that grew so large.
As to why it only occured on the iPhone6 and iPhone6+, I still don't have an answer.
The problematic file was stack-logs.773.1006c8000.REDACTED.wmQj2k.index. It grew to 700MB almost right after login.
Much thanks to #jrturton because his answer really lead to this.

iOS app crashes randomly because of bad install

I've had a fairly large app (50mb) in the App Store for several years now with many updates and thousands of users. Before each release I do a lot of testing, analyzing and beta-testing on all sorts of devices and situations before releasing an update.
Every once in a while I get a horrific bug report that says the app is crashing ALL the time and is completely unusable. What seems to fix this EVERY TIME is telling the user to delete the app, power cycle the device and reinstall the app while under wi-fi.
This means to me that under some unknown circumstances to me, my app is being installed badly. And this has been happening through iOS 4, 5, 6 and now 7.
Is this happening to anyone else? Any known causes or fixes besides my reinstall fix?
To make matters worse, this shows up in a few bad reviews that say the app crashes all the time. All the other reviews are 5 stars! I hate getting blamed for a bad install.
Thanks!
Shot in the dark here, but could it be related to wireless connectivity (ie an API timing out)? Very hard to say without more details.

iOS device computational/memory limit

I'm working on a game for iOS, and to start a new game the following steps are followed:
The user choose the number of pieces
Each piece is created through a loop
The game starts
On the simulator I can choose as many pieces as I want, and start as many games as I want, and the app is working fine.
But on a real device (my new iPad 3), the app crashes if I choose more than 400 pieces, and also if I start (say) 3 games with 150 pieces each. I've checked with breakpoints, it crashes in different lines: sometimes creating a piece, sometimes even after the game started. Unfortunately the console is not telling me anything.
I checked the app with instruments: there are not leaks at all, and the total allocation size is at most 4 MB. And I'm logging in didReceiveMemoryWarning in my AppDelegate, but it looks like it is never called.
My question is: how should I behave to debug this? How can I understand what the computational/memory limits of a iOS device are?
If using too much memory is causing you this problem then try a NSLog in didReciveMemoryWarning. As for the memory limit I already saw a few posts here.
How much memory does iOS allow apps to use?
or
Max application memory Limit in iPad? or
iOS memory allocation - how much memory can be used in an application?
And I think I can find a few more :)

iPad1 memory mystery with my texture-intensive game app

Sorry for the vague title, but not quite sure how to summarize this one.
The facts are:
I have a game that's been approved by Apple and is on the App Store.
It is a universal app. It uses textures designed for 320x480 on small screens, and uses larger textures (roughly four times as large) on retina and iPad screens.
While developing it, I would sometimes see low-memory warnings in the console log, but after reading about these it seemed like they were often somewhat spurious/unimportant, and in any event I was not having crashes, and my testers on a variety of devices (iPod Touch 2nd gen, iPod Touch 4th gen, iPhone3, iPhone4, iPad1, iPad2) were not seeing crashes.
When I started distributing the app to a wider set of beta testers through TestFlightApp, I got reports of some people seeing crashes as the app was loading, or very early after the user had chosen a level from the main menu and the app was loading the level textures. We discovered that if these users just restarted their devices, they didn't have problems any more. Since this was the first time we had seen problems like this, we attributed it to something TestFlightApp was doing, some funny state it was leaving the device in after the install (we talked to TestFlightApp about this and they had never heard of such a thing).
As stated, Apple approved the app and it's on the App Store. Soon after it went live, we got reports from some iPad1 users that it was crashing for them on app load, or soon thereafter, same kind of thing as we saw with certain TestFlightApp users. And again similar to the TestFlightApp users, these customers reported that restarting would often fix the problem. But it wasn't as nice because the problem tended to appear again. One of these users sent me several LowMemory...log files that she got off her PC after synching her iPad. There were about 10 such files, and none of them listed my program in the Processes list. Instead it showed other programs marked as either (active) or (jettisoned), and the "Largest Process" could be anything from MobileSafari to Kobo, but again my own app was never listed. So, I didn't understand that, but the bottom line seems to be that, for this user at least, something is pushing the memory over some limit where my app won't run well.
I have since gone back and talked to one of the TestFlightApp beta testers, and it turns out that he does indeed sometimes get the app crash again, so it wasn't just some residue from TestFlightApp. However, for him the crash is much less frequent than it is for this customer.
Other iPad1 testers of the game have never had any trouble. They report that they play the game for hours each day, use their iPad with several other apps in between, and rarely power it down. Similarly, I never had a crash with my iPod Touch 4th gen, which is similar to the iPad1 in the at it has a hi-res screen but only 256k RAM.
So, it's very mysterious to me what could be so different about these particular users' iPads. It's mysterious that the game works after the device is restarted, but then after some apps have been run the game (sometimes) has trouble loading. My understanding was that if my game demands memory, the OS will auto-close whatever other apps are running, as necessary, to effectively bring the amount of memory back up to the amount that's available on a freshly restarted device. My only conclusion is that after running some apps the device is left in a state where less memory is available because the OS cannot reclaim certain memory blocks or shut down certain apps.
Unfortunately I don't have one of these "misbehaving" devices to develop with. All I can think to do is try to reduce the memory needs of my app by a certain amount, and send it to one of these users who is having trouble and see if it fixes things. That seems like a potentially inefficient approach, however.
Anybody have a better idea?
Sounds like the memory spike during texture loading is what's causing the app to be terminated on some devices. It may well use less memory after everything's loaded than it does right near the end of initial loading. This could be explained by things being pushed to virtual memory, whereas direct texture loading could be bombarding the RAM with way too many allocations. My suggestions would be to:
Be more aggressive with destroying temporary data structures during loading (release a temporary structure the instant all of its useful values have been read/extracted by other things)
For autoreleased objects, keep an NSAutoreleasePool around at all times; you may even want to drain and realloc a pool several times over the course of one method if you use an exceedingly high number of autoreleased objects.
This may sound silly.. intentionally slow down your loading process. If you get rid of parallelized loads (loading multiple objects at once) or possibly insert a manual time delay in your loading thread/methods, this may give the OS more time to push things to virtual memory and thus Watchdog will not detect the app as being a RAM hog.
EDIT: One possible tactic to implement slower loading: if/when you receive a low memory warning, pause or slow loading down for a few seconds to give other apps time to lower their memory usage, then continue loading at normal speed.
Even if I'm wrong (if LowMemory...log files show Virtual+Physical usage and thus your app isn't even doing that much), I would suggest then integrating bug reporting such as QuincyKit so that you get emailed a backtrace and crash description when this bug IS encountered in the wild.

iOS 4.3.2 user reported app crashing on launch

An update of my app has just been approved by Apple and users are now complaining the app does not launch anymore. It also happens to some new users.
I have absolutely no idea where the problem is nor can I reproduce the problem. I have tested the update on various devices (& simulator) before submitting the update: iPhone 2G running 3.1.3, iPod Touch 2G running 4.3 , iPhone 3G and iPhone 4 running 4.3.1. They ALL work as expected. The update has a few new features like random picking photos from user's photo library using AssetsLibrary framework, I have weak-linked the framework to support iOS 3 and the feature does not load until selected by the user so it should not be the problem. After all, the update has been tested and approved by Apple.
I have difficulty collecting crash information from users with the problem, but I know one of them uses iPhone 4 with iOS 4.3.2. A quick google search reveals that iOS 4.3.2 has problems launching third party apps, I suspect my problem has something to do with this but I can not confirm it. I am planning to downgrade my dev iPhone 4 to iOS 4.3.2 to test it.
Does anybody here experienced similar problem? My app's ranking has dropped significantly because of the negative reviews so I need to fix this as soon as possible.
Edit:
There should not be any watch dog problem, I tested the update on the above mentioned devices with and without Xcode/debugger.
Memory management. I can not reproduce the problem (I tried quite hard) so I can not confirm if it's EXC_BAD_ACCESS, I did check reference count and nil released objects (safely release) when applicable, I am absolutely not a pro in memory management so I take it seriously, I checked leaks and allocations with instruments, stress-tested and did memory warning simulations, no problem was found.
I have UIApplicationWillEnterForegroundNotification in -loadview, it's only available after iOS 4.0 so I check if it exists with & operator because I use it.
I do not persist data other than saving facebook connect token and expiry date (NSDate) in NSUserDefaults, since the problem also happens to new users so I think it's something else
We're going to need more info, unfortunately. But just off the top of my head:
Watch dog? What sorts of stuff are you loading when you launch your app? It may be that resources are constrained on the devices having this issue and you are doing work that should be done a separate thread, or otherwise delayed until after the app has launched.
EXC_BAD_ACCESS. There could be a race condition going on that is resulting in most people able to launch OK, but for some it just isn't working because of bad references. I know, you write good code and manage your references like a pro, but sometimes a non-obvious slip-up can creep in.
Are you safely instantiating some types of classes? An example that bit me once was with the MFMailComposeViewController class. Before instantiating you're suppose to call its static method canSendMail. If a user hasn't setup any mail accounts on their device (hard to figure there would be anyone that fits this scenario, but hey! found out after an update that there are quite a few!) then the app would crash.
What data persistence (if any) do you have? Are you using Core Data? Serialized objects in a plist? NSUserDefaults? Your strategy may be corrupting data you are persisting and that is leading to a crash.

Resources