Ionic version: (check one with "x")
[ ] 1.x
[ ] 2.x
[ X] 3.x
I'm submitting a ... (check one with "x")
[X ] bug report
Current behavior:
Basic v3 App. Uses Tabs. One tab is empty, the other instantiates the Media and File plugins.
Switching between tabs causes increasing memory usage that is never released. This practically makes ionic un-usable for deploying a real world application.
We have tried with @IonicPage decorators / modules / lazy loading and also without and eagerly loading the pages instead... same result for both although eagerly loading seems worse.
Expected behavior:
When exiting the Tab (or modal, we have tried both) the audio instance is released, this should clear up memory but it does not.
It could also be that the memory issue is unrelated to the Media and/or File plugins ... we have no way of knowing without hiring a native developer really ... the whole reason we are attempting to use Ionic is to avoid having to hire a Native Developer in the first place though right?
Steps to reproduce:
See this link in the forum, albeit, please excuse the frustration we expressed in the thread:
https://forum.ionicframework.com/t/cordova-ionic-2-3-sadly-unusable-on-ios-please-tell-me-i-am-wrong/88339/8
Related code:
See this repo: https://github.com/gitdisrupt/Ionic3iOSMemoryIssue
Other information:
Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):
Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.9.0
Xcode version: Xcode 8.3 Build version 8W120l
With the media plugin you have to call the release function to release the underlying system resources. Not sure if that is the cause but something to note
What platform is this? In your repo, where should we be looking?
I'm thinking based off the title of the Issue as well as the linked repository, iOS 10.
Yes, iOS 10 ...
And yes, that demo does in-fact release the audio instance...
IMPORTANT to note though ... it is very possible the memory increases have nothing to do with the media or file plugins ... could just be an Angular / Ionic leak somewhere?
I'll try to do similar tests without implementing those plugins when i have time.
@gitdisrupt there was a patch for memory leak in the scroll function that just went into ionic 3.1 I think? Maybe update to 3.1.1 a d see if it is still reproducible?
Ich have the Same Problem
I had this problem also, But only when selection photos or taking photos (media and camera plugins)
Each photo that was loaded to the app causes an increase in memory usage.
Eventual I solved it by manually deleting the cache folder that the app loads the media to.
Hello @gitdisrupt , sorry your having issues. We will look into this. I have pinged @manucorporat (our resident iOS expert) about this issue. Have you tried updating to WKWebView as he mentioned here. ?
I did try updating to the WKWebView ... it created other issues ... but the memory usage was still ever increasing anyway, so i reverted back to the UIWebView.
Hello @gitdisrupt , just wanted to let you know I'm looking into this issue as I type this. Will have results of my testing to share here shortly.
Alright so here is what I'm seeing in my testing:

This is your example repo @gitdisrupt , but with a blank modal that I added being opened over and over. In this graph you can see that memory usage does rise slightly everytime the modal is opened and closed, but you can also see that this graph looks like "mountains". If there was a memory leak in modal it would look more like a staircase because no memory would be getting freed. The reason we see a slight memory increase here is simply iOS seeing that we have lots of memory overhead so it says "Hey, I have lots of memory available and I see a process is periodically using more memory than the baseline so for better perf I'm gonna allocate a little more memory to this process". Now, I'm not trying to say that our code is totally memory safe, cause almost no piece of software is, I'm just saying from this graph it does not look like the memory issues you're seeing are coming from our code.

Now, this result (the second group of "mountains" in this graph) I am opening the recording modal, recording a short audio clip and then closing the modal. We can see here that memory usage definitely rises much faster and less seems to get released. Also, the longer I record the less memory seems to be release once I close the modal. To me, this points to the cordova media plugin having a memory leak.
I am going to wait on a second opinion from @manucorporat before closing this issue, but it is my opinion from what I have seen in my testing that the cordova media plugin seems to have a smallish memory leak.
Thank you sincerely for taking the time to look into this... mountains aside, there is still a slight increase in memory there that is never released ... but ... maybe before going any further with this .... I believe media recording may be confusing the issue.
It might be the modal itself thats causing the memory leak....
I have created a much simpler demo that does not implement recording at all.
It seems scrolling in the most basic version of an ionic app creates memory leaks. I will open this as a separate issue.
here it is .... Maybe this should be addressed first?
https://github.com/driftyco/ionic/issues/11570
Hello @gitdisrupt I am going to close this issue as a duplicate of #11570 so as to bring all the memory related issues together into one tracking issue.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Most helpful comment
I had this problem also, But only when selection photos or taking photos (media and camera plugins)
Each photo that was loaded to the app causes an increase in memory usage.
Eventual I solved it by manually deleting the cache folder that the app loads the media to.