[TIMOB-24206] iOS: Memory leaks after select camera or photo gallery with jscore framework
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-05-23T08:38:59.000+0000 |
Affected Version/s | Release 6.0.0, Release 5.5.1 |
Fix Version/s | Release 7.3.0 |
Components | iOS |
Labels | ios |
Reporter | Hazem Khaled |
Assignee | Hans Knöchel |
Created | 2016-12-10T07:20:45.000+0000 |
Updated | 2018-07-10T01:11:29.000+0000 |
Description
If
<use-jscore-framework>false</use-jscore-framework>
memory leaking happen after selecting image or capture picture from camera,
attached memory allocation after selecting 10 images from photo gallery, with true/false for run-on-main-thread
, use-auto-layout
and use-jscore-framework
, I think the problem in last one.
<property name="run-on-main-thread" type="bool">true</property>
<ios>
<enable-launch-screen-storyboard>true</enable-launch-screen-storyboard>
<use-app-thinning>true</use-app-thinning>
<use-jscore-framework>false</use-jscore-framework>
<use-auto-layout>true</use-auto-layout>
<ios>
var win = Ti.UI.createWindow(),
button = Ti.UI.createButton({
title: 'Open Gallery',
});
button.addEventListener('click', function() {
Ti.Media.openPhotoGallery({
mediaTypes: Ti.Media.MEDIA_TYPE_PHOTO,
success: function(e) {
win.backgroundImage = e.media;
}
});
});
win.add(button);
win.open();
Attachments
File | Date | Size |
---|---|---|
1. main=false jscore=false autoLayout=false.png | 2016-12-10T07:16:43.000+0000 | 635739 |
1. main=false jscore=false autoLayout=true.png | 2016-12-10T07:16:40.000+0000 | 637833 |
1. main=false jscore=true autoLayout=true.png | 2016-12-10T07:16:40.000+0000 | 634482 |
1. main=true jscore=false autoLayout=false.png | 2016-12-10T07:16:37.000+0000 | 638313 |
1. main=true jscore=false autoLayout=true.png | 2016-12-10T07:16:38.000+0000 | 638644 |
1. main=true jscore=true autoLayout=true.png | 2016-12-10T07:16:39.000+0000 | 685247 |
example-jscore-released.png | 2018-02-03T16:04:36.000+0000 | 24041 |
Jscore_Krollobject_for_Tiblob_3d0.png | 2017-03-14T10:28:30.000+0000 | 334939 |
Jscore_Tiblob_3d0.png | 2017-03-14T10:28:30.000+0000 | 294628 |
Kroll.png | 2017-03-14T10:28:30.000+0000 | 402736 |
TIblob.png | 2017-03-14T10:28:30.000+0000 | 407668 |
Note: This PR also resolves an issue where the picker was closed after a 0.5s delay. I refactored it to close the dialog on the main-thread again, so it won't cause problems and gives a better performance as well. PR: https://github.com/appcelerator/titanium_mobile/pull/8676 *Steps to test*: 1. Ensure to enable JSCore as stated in the ticket description 2. Start Instruments > Allocations to monitor memory allocations 3. Run the following test-case
Expected result: The memory should be deallocated to the same state as before after closing the picker. Also, the alert-dialog should be shown after the picker is closed.
[~hazemkhaled] I was also wondering if this was happening with Ti SDK 5.5.1?
@hans, tester report it just after 6, don't know what was before, but i'll test again tomorrow on 5.5.1
Thanks! And please also check if the patch works for you
alert-dialog appear after picker closed, but ram still as is, started 10 MB end with 290 MB sdk: 6.0.1.v20161217061750
[~hazemkhaled] As said on Slack, the PR is not merged, yet and would need to be patched with your current SDK (e.g. replace the MediaModule.m with the contents of [this diff](https://github.com/appcelerator/titanium_mobile/pull/8676/files)). *If* it works, we would merge it. As 6.0.1 is already here ion Wednesday, it won't make it there anymore by now.
Sorry for that, now fine memory deallocated start 17 MB end with 36 MB after pick 10 photos Thanks
Thanks man! [~vijaysingh] will continue with the review then.
[~hazemkhaled] Can you do me a favor and test TIMOB-24270 regarding your leaks as well? This one caused a small regression I'd like to get rid of asap. Thx!
Verified fix with the test case provided above by [~hansknoechel] was able to see memory being deallocated, started at 10mb and ended at 37mb (5 photos selected). (Tested using Xcode Instruments (Allocations). *Environement*
Reopening issue together with [this PR](https://github.com/appcelerator/titanium_mobile/pull/8783), since it's causing major other issues for running on kroll-thread (TIMOB-24270). Will re-investigate this one.
I have attached memory graph of TiBlob and KrollObject with and without jscore.Which shows the difference in referencing of memory. [~hansknoechel] let us discuss on this. Probably it can help on our debugging.
Work has been ongoing on this, with no proper solution. As of now, it will not make the schedule for 6.2.0. Apologies, we will continue to work on this.
Any updates / timeline on this issue? Extensive camera use in the app is causing app to lock up and/or sometime no longer auto focus.
[~NewportSolutions] We are looking in this problem to find a proper solution for this. The problem is happening only if-
Some observations and thoughts after spending more time on that the last week: I tested again using three images and - they are actually removed (not directly, but after being autoreleased). See the following image with some markers that indicate the different states (click to expand): !example-jscore-released.png|thumbnail! And in case this really still an issue, couldn't we just pull in [the initial PR](https://github.com/appcelerator/titanium_mobile/pull/8676) again and wrap it to only be used when using main-thread + jscore (instead of allowing the kroll-thread, too, which caused the revert of the PR as noted above in the comments)? The kroll-thread will go away this year anyway and since main-thread is the default now, I don't see many reasons not to do it.
Hans, This is exactly what I thought was causing my "file upload issue" that I mentioned on LinkedIn. I isolated the crash/freeze cause - taking photos before the upload. Uploading the same photo is no problem. Taking new photo before each upload causes the app crashes / freeze. I added _{color:#d04437}
[~hknoechel] Your proposal sounds good. Would you like to create PR for this? Thanks!
[~hknoechel] I verified your proposal and found following result - 1. On iOS 11.2 , with main-thread and Jscore, TiBlob get released after approx. 3 mints. It looks some changes has made in JavaScriptCore framework from apple side. But if we continue selecting more images, it doesn't get released. 2. On iOS 10.3.1, with main-thread and Jscore, TiBlob get released after approx. 12 mints. 3. On iOS 10.0, with main-thread and Jscore, TiBlob didn't get released even after 20 mints. 4. If we use [image autorelease] in point 1 & 2, it will crash the app.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/9850 PR (7_1_X): https://github.com/appcelerator/titanium_mobile/pull/9851
It turned out that there can still be leaks on larger data uploads, so I'll put it back to
In Progress
and investigate it for the next patch.*Closing ticket.* Verified fix in SDK Version
7.3.0.v20180613110103
. *FR Passed* Using the test case mentioned in the description each image added would increase the memory each time and after a certain time the images will be autoreleased; autoreleasing no longer causes the application to crash. *Test Environment*