Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24206] iOS: Memory leaks after select camera or photo gallery with jscore framework

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-05-23T08:38:59.000+0000
Affected Version/sRelease 6.0.0, Release 5.5.1
Fix Version/sRelease 7.3.0
ComponentsiOS
Labelsios
ReporterHazem Khaled
AssigneeHans Knöchel
Created2016-12-10T07:20:45.000+0000
Updated2018-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

FileDateSize
1. main=false jscore=false autoLayout=false.png2016-12-10T07:16:43.000+0000635739
1. main=false jscore=false autoLayout=true.png2016-12-10T07:16:40.000+0000637833
1. main=false jscore=true autoLayout=true.png2016-12-10T07:16:40.000+0000634482
1. main=true jscore=false autoLayout=false.png2016-12-10T07:16:37.000+0000638313
1. main=true jscore=false autoLayout=true.png2016-12-10T07:16:38.000+0000638644
1. main=true jscore=true autoLayout=true.png2016-12-10T07:16:39.000+0000685247
example-jscore-released.png2018-02-03T16:04:36.000+000024041
Jscore_Krollobject_for_Tiblob_3d0.png2017-03-14T10:28:30.000+0000334939
Jscore_Tiblob_3d0.png2017-03-14T10:28:30.000+0000294628
Kroll.png2017-03-14T10:28:30.000+0000402736
TIblob.png2017-03-14T10:28:30.000+0000407668

Comments

  1. Hans Knöchel 2016-12-10

    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
       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;
                   alert("DONE");
               }
           });
       });
        
       win.add(button);
       win.open();
       
    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.
  2. Hans Knöchel 2016-12-10

    [~hazemkhaled] I was also wondering if this was happening with Ti SDK 5.5.1?
  3. Hazem Khaled 2016-12-10

    @hans, tester report it just after 6, don't know what was before, but i'll test again tomorrow on 5.5.1
  4. Hans Knöchel 2016-12-11

    Thanks! And please also check if the patch works for you
  5. Hazem Khaled 2016-12-19

    alert-dialog appear after picker closed, but ram still as is, started 10 MB end with 290 MB sdk: 6.0.1.v20161217061750
  6. Hans Knöchel 2016-12-19

    [~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.
  7. Hazem Khaled 2016-12-19

    Sorry for that, now fine memory deallocated start 17 MB end with 36 MB after pick 10 photos Thanks
  8. Hans Knöchel 2016-12-19

    Thanks man! [~vijaysingh] will continue with the review then.
  9. Hans Knöchel 2017-01-03

    [~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!
  10. Samir Mohammed 2017-01-18

    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*
        Appcelerator Command-Line Interface, version 6.1.0
        Iphone SE (10.2) Simulator 
        Operating System Name: Mac OS X El Capitan
        Operating System Version: 10.11.6
        Node.js Version: 4.6.0
        npm: 4.2.8
        Titanium SDK Version: 6.1.0.v20170115172707
        Xcode: 8.2
        Appcelerator Studio: 4.8.1.201612050850
        
  11. Hans Knöchel 2017-01-24

    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.
  12. Vijay Singh 2017-03-14

    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.
  13. Eric Merriman 2017-08-09

    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.
  14. Joe 2017-09-13

    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.
  15. Vijay Singh 2017-09-14

    [~NewportSolutions] We are looking in this problem to find a proper solution for this. The problem is happening only if- true in tiapp.xml. Can you try with - false in your tiapp.xml. Thanks.
  16. Hans Knöchel 2018-02-03

    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.
  17. Joe 2018-02-04

    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}false{color}_ and now I am taking 20+ photos without issue and seeing the memory released in instruments. I agree this needs to be fixed as you suggested.
  18. Vijay Singh 2018-02-05

    [~hknoechel] Your proposal sounds good. Would you like to create PR for this? Thanks!
  19. Vijay Singh 2018-02-14

    [~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.
  20. Hans Knöchel 2018-02-16

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/9850 PR (7_1_X): https://github.com/appcelerator/titanium_mobile/pull/9851
  21. Hans Knöchel 2018-02-21

    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.
  22. Samir Mohammed 2018-07-10

    *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*
        APPC Studio: 5.0.0.201712081732
        APPC CLI: 7.0.4
        iPhone 6 simulator (11.2)
        Operating System Name: Mac OS High Sierra
        Operating System Version: 10.13
        Node.js Version: 8.9.1
        Xcode 9.2
        

JSON Source