New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing modal page with image background leads to Out Of Memory error #2147

Closed
tsonevn opened this Issue May 19, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@tsonevn
Contributor

tsonevn commented May 19, 2016

Can't fix this issue in tns-core-modules. This is a problem of the Android Runtime. For more information see NativeScript/android-runtime#503

Which platform(s) does your issue occur on?

Android

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.0.0
  • tns-core-modules:2.0.0
  • tns-android:2.0.0
  • Plugin(s): no

    Please tell us how to recreate the issue in as much detail as possible.

Every time when the modal page with background image is shown, the Allocated Heap is increased, and this will lead to java.lang.OutOfMemoryErrorerror and the image in background will disappear .

Problem reproduced here:project

@hamorphis hamorphis self-assigned this Jun 8, 2016

@hamorphis

This comment has been minimized.

Show comment
Hide comment
@hamorphis

hamorphis Jun 13, 2016

Contributor

Application that isolates the problem: https://github.com/hamorphis/modal-memory-leak

Contributor

hamorphis commented Jun 13, 2016

Application that isolates the problem: https://github.com/hamorphis/modal-memory-leak

@hamorphis

This comment has been minimized.

Show comment
Hide comment
@hamorphis

hamorphis Jun 13, 2016

Contributor

Until we understand why this happens, there is a quick workaround to avoid the OutOfMemoryException. Simply call gc() in the modal closed callback like this:

page.showModal("./modal-page", undefined, function onCloseCallback() {
        gc();
}, true);

This will collect the bitmaps and free memory.

Contributor

hamorphis commented Jun 13, 2016

Until we understand why this happens, there is a quick workaround to avoid the OutOfMemoryException. Simply call gc() in the modal closed callback like this:

page.showModal("./modal-page", undefined, function onCloseCallback() {
        gc();
}, true);

This will collect the bitmaps and free memory.

@slavchev

This comment has been minimized.

Show comment
Hide comment
@slavchev

slavchev Jun 22, 2016

After investigation it turned out there is not leaks both on JavaScript and Java sides. It seems that AdjustAmountOfExternalAllocatedMemory doesn't help. Maybe Application.onLowMemory will work better.

slavchev commented Jun 22, 2016

After investigation it turned out there is not leaks both on JavaScript and Java sides. It seems that AdjustAmountOfExternalAllocatedMemory doesn't help. Maybe Application.onLowMemory will work better.

@slavchev slavchev removed their assignment Jun 22, 2016

@hamorphis

This comment has been minimized.

Show comment
Hide comment
@hamorphis

hamorphis Jun 28, 2016

Contributor

I tried the following experiment. Each time an Android Bitmap was loaded into memory, I allocated a JavaScript array as a private field in ImageSource with the same size as the Bitmap in order to pressure V8 garbage collector. Unfortunately, at some point of time, V8 crashed ugly.

image-source.android.ts

    private _android: android.graphics.Bitmap;
    private _androidMemoryConsumer: Array<number>;

    public get android(): android.graphics.Bitmap {
        return this._android;
    }

    public set android(value: android.graphics.Bitmap) {
        if (this._android !== value){
            this._android = value;
            this._allocateMemoryConsumer();
        }    
    }

    // Allocate a JS array of the same size as the Bitmap in order to pressure the V8 garbage collector.
    private _allocateMemoryConsumer(){
        if (!this.android){
            this._androidMemoryConsumer = undefined;
            return;
        }

        // 1 JS number is 8 bytes
        let length = ImageSource._getBitmapByteCount(this.android) / 8;
        this._androidMemoryConsumer = new Array<number>();
        console.log(`>>> ${this}._androidMemoryConsumer = new Array<number>(${length});`);
        for (let i = 0; i < length; i++){
            this._androidMemoryConsumer[i] = 42;
        }
    }

    private static _getBitmapByteCount(bitmap: android.graphics.Bitmap): number {
        if ((<any>bitmap).getAllocationByteCount){
            // API Level 19 and up
            return (<any>bitmap).getAllocationByteCount();
        }
        else {
            return bitmap.getByteCount();
        }
    }

THE CRASH

--------- beginning of crash
06-28 15:38:41.206  5040  5040 F libc    : Fatal signal 4 (SIGILL), code 2, fault addr 0xa19ea049 in tid 5040 (modalmemoryleak)
06-28 15:38:41.316  1196  1196 I SELinux : SELinux: Loaded file_contexts contexts from /file_contexts.
06-28 15:38:41.317  1196  1196 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-28 15:38:41.317  1196  1196 F DEBUG   : Build fingerprint: 'Android/sdk_phone_x86/generic_x86:6.0/MASTER/2780065:userdebug/test-keys'
06-28 15:38:41.317  1196  1196 F DEBUG   : Revision: '0'
06-28 15:38:41.317  1196  1196 F DEBUG   : ABI: 'x86'
06-28 15:38:41.319  1196  1196 F DEBUG   : pid: 5040, tid: 5040, name: modalmemoryleak  >>> org.nativescript.modalmemoryleak <<<
06-28 15:38:41.319  1196  1196 F DEBUG   : signal 4 (SIGILL), code 2 (ILL_ILLOPN), fault addr 0xa19ea049
06-28 15:38:41.316  1196  1196 W debuggerd: type=1400 audit(0.0:7): avc: denied { search } for name="org.nativescript.modalmemoryleak" dev="vdc" ino=21293 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-28 15:38:41.333  1196  1196 F DEBUG   :     eax 00000057  ebx a1c24cd0  ecx 000013b0  edx 00000000
06-28 15:38:41.333  1196  1196 F DEBUG   :     esi aa192000  edi aa192010
06-28 15:38:41.333  1196  1196 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000007  xss 0000007b
06-28 15:38:41.333  1196  1196 F DEBUG   :     eip a19ea049  ebp bffa9a77  esp bffa9770  flags 00210202
06-28 15:38:41.341  1196  1196 F DEBUG   : 
06-28 15:38:41.341  1196  1196 F DEBUG   : backtrace:
06-28 15:38:41.341  1196  1196 F DEBUG   :     #00 pc 0082b049  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::base::OS::Abort()+25)
06-28 15:38:41.336  1196  1196 W debuggerd: type=1400 audit(0.0:8): avc: denied { search } for name="org.nativescript.modalmemoryleak" dev="vdc" ino=21293 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-28 15:38:41.341  1196  1196 F DEBUG   :     #01 pc 002fff02  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::Utils::ReportApiFailure(char const*, char const*)+114)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #02 pc 00300101  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::V8::FatalProcessOutOfMemory(char const*, bool)+481)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #03 pc 00404844  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Heap::FatalProcessOutOfMemory(char const*, bool)+36)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #04 pc 003c1fb5  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag)+501)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #05 pc 005102ef  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::DeoptimizationInputData::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag)+63)
06-28 15:38:41.343  1196  1196 F DEBUG   :     #06 pc 0065d655  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::LCodeGen::PopulateDeoptimizationData(v8::internal::Handle<v8::internal::Code>)+85)
06-28 15:38:41.343  1196  1196 F DEBUG   :     #07 pc 0065da36  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::LCodeGen::FinishCode(v8::internal::Handle<v8::internal::Code>)+102)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #08 pc 004f8adb  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::LChunk::Codegen()+763)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #09 pc 003767b4  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::OptimizedCompileJob::GenerateCode()+180)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #10 pc 00378d7f  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Compiler::GetConcurrentlyOptimizedCode(v8::internal::OptimizedCompileJob*)+447)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #11 pc 00557203  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions()+419)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #12 pc 003bd85f  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::StackGuard::HandleInterrupts()+479)
06-28 15:38:41.349  1196  1196 F DEBUG   :     #13 pc 0075930e  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*)+62)
06-28 15:38:41.349  1196  1196 F DEBUG   :     #14 pc 0000007b  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #15 pc 00085ec7  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #16 pc 00010ce0  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #17 pc 0000fa7e  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #18 pc 003bc2dc  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so
06-28 15:38:41.349  1196  1196 F DEBUG   :     #19 pc 003bced8  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*)+120)
06-28 15:38:41.349  1196  1196 F DEBUG   :     #20 pc 00321f5b  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*)+251)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #21 pc 003220fd  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::Function::Call(v8::Local<v8::Value>, int, v8::Local<v8::Value>*)+93)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #22 pc 0028207b  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (tns::CallbackHandlers::CallJSMethod(v8::Isolate*, _JNIEnv*, v8::Local<v8::Object> const&, std::string const&, _jobjectArray*)+635)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #23 pc 002aae06  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (tns::Runtime::CallJSMethodNative(_JNIEnv*, _jobject*, int, _jstring*, int, unsigned char, _jobjectArray*)+406)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #24 pc 0027ac3e  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (Java_com_tns_Runtime_callJSMethodNative+222)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #25 pc 005a49f4  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[])+200)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #26 pc 005a5724  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.dispatchCallJSMethodNative(int, java.lang.String, boolean, long, java.lang.Class, java.lang.Object[])+584)
06-28 15:38:41.353  1196  1196 F DEBUG   :     #27 pc 005a484f  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethodImpl(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[])+1171)
06-28 15:38:41.355  1196  1196 F DEBUG   :     #28 pc 005a40f2  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[])+246)
06-28 15:38:41.355  1196  1196 F DEBUG   :     #29 pc 005a41ca  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, java.lang.Object[])+158)
06-28 15:38:41.355  1196  1196 F DEBUG   :     #30 pc 005a4266  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object[])+90)
06-28 15:38:41.357  1196  1196 F DEBUG   :     #31 pc 000005b7  /data/data/org.nativescript.modalmemoryleak/code_cache/secondary-dexes/odex/com.tns.gen.android.app.DialogFragment_frnal_ts_helpers_l55_c38__DialogFragmentClassInner (offset 0x2000)
06-28 15:38:41.357  1196  1196 F DEBUG   :     #32 pc 00072bc8  <unknown>
06-28 15:38:41.835  1196  1196 F DEBUG   : 
06-28 15:38:41.835  1196  1196 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_02
06-28 15:38:41.835  1196  1196 E DEBUG   : AM write failed: Broken pipe
--------- beginning of system
06-28 15:38:41.836  1545  1562 I BootReceiver: Copying /data/tombstones/tombstone_02 to DropBox (SYSTEM_TOMBSTONE)
06-28 15:38:41.840  1545  5075 W ActivityManager:   Force finishing activity org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity
06-28 15:38:41.852  1545  5075 D         : HostConnection::get() New Host Connection established 0x9e6363d0, tid 5075
06-28 15:38:41.857  1545  1562 W DropBoxManagerService: Dropping: SYSTEM_TOMBSTONE (10 > 0 bytes)
06-28 15:38:41.862  1545  5076 W DropBoxManagerService: Dropping: data_app_native_crash (10 > 0 bytes)
06-28 15:38:41.870  1189  1189 E EGL_emulation: tid 1189: eglCreateSyncKHR(1315): error 0x3004 (EGL_BAD_ATTRIBUTE)
06-28 15:38:41.924  1545  5075 E JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 104)
06-28 15:38:41.924  1545  5075 W ActivityManager: Exception thrown during pause
06-28 15:38:41.924  1545  5075 W ActivityManager: android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
06-28 15:38:41.924  1545  5075 W ActivityManager:   at android.os.BinderProxy.transactNative(Native Method)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at android.os.BinderProxy.transact(Binder.java:503)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at android.app.ApplicationThreadProxy.schedulePauseActivity(ApplicationThreadNative.java:727)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:867)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:2907)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStack.finishTopRunningActivityLocked(ActivityStack.java:2763)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStackSupervisor.finishTopRunningActivityLocked(ActivityStackSupervisor.java:2755)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:11971)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:11867)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:12556)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:12063)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
06-28 15:38:41.929  1545  1564 E JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 60)
06-28 15:38:41.939  1202  1202 I Zygote  : Process 5040 exited due to signal (4)
06-28 15:38:41.939  1545  1583 W InputDispatcher: channel 'd92372c org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
06-28 15:38:41.939  1545  1583 E InputDispatcher: channel 'd92372c org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
06-28 15:38:41.946  1545  1556 D GraphicsStats: Buffer count: 3
06-28 15:38:41.946  1545  1665 I WindowState: WIN DEATH: Window{d92372c u0 org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity}
06-28 15:38:41.946  1545  1665 W InputDispatcher: Attempted to unregister already unregistered input channel 'd92372c org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity (server)'
06-28 15:38:41.958  1189  1449 E SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
06-28 15:38:41.959  1545  5078 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-28 15:38:41.963  1545  1663 I ActivityManager: Process org.nativescript.modalmemoryleak (pid 5040) has died
06-28 15:38:41.998  1545  5078 D         : HostConnection::get() New Host Connection established 0x9e4fc300, tid 5078
06-28 15:38:42.036  1545  5078 I OpenGLRenderer: Initialized EGL, version 1.4
06-28 15:38:42.571  1787  2023 W OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
06-28 15:38:42.677  1545  1564 W WindowAnimator: Failed to dispatch window animation state change.
06-28 15:38:42.677  1545  1564 W WindowAnimator: android.os.DeadObjectException
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.BinderProxy.transactNative(Native Method)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.BinderProxy.transact(Binder.java:503)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.IWindow$Stub$Proxy.onAnimationStopped(IWindow.java:534)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator.updateWindowsLocked(WindowAnimator.java:286)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator.animateLocked(WindowAnimator.java:678)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator.-wrap0(WindowAnimator.java)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator$1.doFrame(WindowAnimator.java:123)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:856)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer.doFrame(Choreographer.java:603)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.Handler.handleCallback(Handler.java:739)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.Handler.dispatchMessage(Handler.java:95)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.Looper.loop(Looper.java:148)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.HandlerThread.run(HandlerThread.java:61)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.ServiceThread.run(ServiceThread.java:46)
Contributor

hamorphis commented Jun 28, 2016

I tried the following experiment. Each time an Android Bitmap was loaded into memory, I allocated a JavaScript array as a private field in ImageSource with the same size as the Bitmap in order to pressure V8 garbage collector. Unfortunately, at some point of time, V8 crashed ugly.

image-source.android.ts

    private _android: android.graphics.Bitmap;
    private _androidMemoryConsumer: Array<number>;

    public get android(): android.graphics.Bitmap {
        return this._android;
    }

    public set android(value: android.graphics.Bitmap) {
        if (this._android !== value){
            this._android = value;
            this._allocateMemoryConsumer();
        }    
    }

    // Allocate a JS array of the same size as the Bitmap in order to pressure the V8 garbage collector.
    private _allocateMemoryConsumer(){
        if (!this.android){
            this._androidMemoryConsumer = undefined;
            return;
        }

        // 1 JS number is 8 bytes
        let length = ImageSource._getBitmapByteCount(this.android) / 8;
        this._androidMemoryConsumer = new Array<number>();
        console.log(`>>> ${this}._androidMemoryConsumer = new Array<number>(${length});`);
        for (let i = 0; i < length; i++){
            this._androidMemoryConsumer[i] = 42;
        }
    }

    private static _getBitmapByteCount(bitmap: android.graphics.Bitmap): number {
        if ((<any>bitmap).getAllocationByteCount){
            // API Level 19 and up
            return (<any>bitmap).getAllocationByteCount();
        }
        else {
            return bitmap.getByteCount();
        }
    }

THE CRASH

--------- beginning of crash
06-28 15:38:41.206  5040  5040 F libc    : Fatal signal 4 (SIGILL), code 2, fault addr 0xa19ea049 in tid 5040 (modalmemoryleak)
06-28 15:38:41.316  1196  1196 I SELinux : SELinux: Loaded file_contexts contexts from /file_contexts.
06-28 15:38:41.317  1196  1196 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-28 15:38:41.317  1196  1196 F DEBUG   : Build fingerprint: 'Android/sdk_phone_x86/generic_x86:6.0/MASTER/2780065:userdebug/test-keys'
06-28 15:38:41.317  1196  1196 F DEBUG   : Revision: '0'
06-28 15:38:41.317  1196  1196 F DEBUG   : ABI: 'x86'
06-28 15:38:41.319  1196  1196 F DEBUG   : pid: 5040, tid: 5040, name: modalmemoryleak  >>> org.nativescript.modalmemoryleak <<<
06-28 15:38:41.319  1196  1196 F DEBUG   : signal 4 (SIGILL), code 2 (ILL_ILLOPN), fault addr 0xa19ea049
06-28 15:38:41.316  1196  1196 W debuggerd: type=1400 audit(0.0:7): avc: denied { search } for name="org.nativescript.modalmemoryleak" dev="vdc" ino=21293 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-28 15:38:41.333  1196  1196 F DEBUG   :     eax 00000057  ebx a1c24cd0  ecx 000013b0  edx 00000000
06-28 15:38:41.333  1196  1196 F DEBUG   :     esi aa192000  edi aa192010
06-28 15:38:41.333  1196  1196 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000007  xss 0000007b
06-28 15:38:41.333  1196  1196 F DEBUG   :     eip a19ea049  ebp bffa9a77  esp bffa9770  flags 00210202
06-28 15:38:41.341  1196  1196 F DEBUG   : 
06-28 15:38:41.341  1196  1196 F DEBUG   : backtrace:
06-28 15:38:41.341  1196  1196 F DEBUG   :     #00 pc 0082b049  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::base::OS::Abort()+25)
06-28 15:38:41.336  1196  1196 W debuggerd: type=1400 audit(0.0:8): avc: denied { search } for name="org.nativescript.modalmemoryleak" dev="vdc" ino=21293 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-28 15:38:41.341  1196  1196 F DEBUG   :     #01 pc 002fff02  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::Utils::ReportApiFailure(char const*, char const*)+114)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #02 pc 00300101  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::V8::FatalProcessOutOfMemory(char const*, bool)+481)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #03 pc 00404844  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Heap::FatalProcessOutOfMemory(char const*, bool)+36)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #04 pc 003c1fb5  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag)+501)
06-28 15:38:41.341  1196  1196 F DEBUG   :     #05 pc 005102ef  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::DeoptimizationInputData::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag)+63)
06-28 15:38:41.343  1196  1196 F DEBUG   :     #06 pc 0065d655  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::LCodeGen::PopulateDeoptimizationData(v8::internal::Handle<v8::internal::Code>)+85)
06-28 15:38:41.343  1196  1196 F DEBUG   :     #07 pc 0065da36  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::LCodeGen::FinishCode(v8::internal::Handle<v8::internal::Code>)+102)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #08 pc 004f8adb  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::LChunk::Codegen()+763)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #09 pc 003767b4  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::OptimizedCompileJob::GenerateCode()+180)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #10 pc 00378d7f  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Compiler::GetConcurrentlyOptimizedCode(v8::internal::OptimizedCompileJob*)+447)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #11 pc 00557203  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions()+419)
06-28 15:38:41.345  1196  1196 F DEBUG   :     #12 pc 003bd85f  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::StackGuard::HandleInterrupts()+479)
06-28 15:38:41.349  1196  1196 F DEBUG   :     #13 pc 0075930e  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*)+62)
06-28 15:38:41.349  1196  1196 F DEBUG   :     #14 pc 0000007b  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #15 pc 00085ec7  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #16 pc 00010ce0  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #17 pc 0000fa7e  <unknown>
06-28 15:38:41.349  1196  1196 F DEBUG   :     #18 pc 003bc2dc  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so
06-28 15:38:41.349  1196  1196 F DEBUG   :     #19 pc 003bced8  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*)+120)
06-28 15:38:41.349  1196  1196 F DEBUG   :     #20 pc 00321f5b  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*)+251)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #21 pc 003220fd  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (v8::Function::Call(v8::Local<v8::Value>, int, v8::Local<v8::Value>*)+93)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #22 pc 0028207b  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (tns::CallbackHandlers::CallJSMethod(v8::Isolate*, _JNIEnv*, v8::Local<v8::Object> const&, std::string const&, _jobjectArray*)+635)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #23 pc 002aae06  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (tns::Runtime::CallJSMethodNative(_JNIEnv*, _jobject*, int, _jstring*, int, unsigned char, _jobjectArray*)+406)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #24 pc 0027ac3e  /data/app/org.nativescript.modalmemoryleak-1/lib/x86/libNativeScript.so (Java_com_tns_Runtime_callJSMethodNative+222)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #25 pc 005a49f4  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[])+200)
06-28 15:38:41.352  1196  1196 F DEBUG   :     #26 pc 005a5724  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.dispatchCallJSMethodNative(int, java.lang.String, boolean, long, java.lang.Class, java.lang.Object[])+584)
06-28 15:38:41.353  1196  1196 F DEBUG   :     #27 pc 005a484f  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethodImpl(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[])+1171)
06-28 15:38:41.355  1196  1196 F DEBUG   :     #28 pc 005a40f2  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[])+246)
06-28 15:38:41.355  1196  1196 F DEBUG   :     #29 pc 005a41ca  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, java.lang.Object[])+158)
06-28 15:38:41.355  1196  1196 F DEBUG   :     #30 pc 005a4266  /data/app/org.nativescript.modalmemoryleak-1/oat/x86/base.odex (offset 0x3b8000) (java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object[])+90)
06-28 15:38:41.357  1196  1196 F DEBUG   :     #31 pc 000005b7  /data/data/org.nativescript.modalmemoryleak/code_cache/secondary-dexes/odex/com.tns.gen.android.app.DialogFragment_frnal_ts_helpers_l55_c38__DialogFragmentClassInner (offset 0x2000)
06-28 15:38:41.357  1196  1196 F DEBUG   :     #32 pc 00072bc8  <unknown>
06-28 15:38:41.835  1196  1196 F DEBUG   : 
06-28 15:38:41.835  1196  1196 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_02
06-28 15:38:41.835  1196  1196 E DEBUG   : AM write failed: Broken pipe
--------- beginning of system
06-28 15:38:41.836  1545  1562 I BootReceiver: Copying /data/tombstones/tombstone_02 to DropBox (SYSTEM_TOMBSTONE)
06-28 15:38:41.840  1545  5075 W ActivityManager:   Force finishing activity org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity
06-28 15:38:41.852  1545  5075 D         : HostConnection::get() New Host Connection established 0x9e6363d0, tid 5075
06-28 15:38:41.857  1545  1562 W DropBoxManagerService: Dropping: SYSTEM_TOMBSTONE (10 > 0 bytes)
06-28 15:38:41.862  1545  5076 W DropBoxManagerService: Dropping: data_app_native_crash (10 > 0 bytes)
06-28 15:38:41.870  1189  1189 E EGL_emulation: tid 1189: eglCreateSyncKHR(1315): error 0x3004 (EGL_BAD_ATTRIBUTE)
06-28 15:38:41.924  1545  5075 E JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 104)
06-28 15:38:41.924  1545  5075 W ActivityManager: Exception thrown during pause
06-28 15:38:41.924  1545  5075 W ActivityManager: android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
06-28 15:38:41.924  1545  5075 W ActivityManager:   at android.os.BinderProxy.transactNative(Native Method)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at android.os.BinderProxy.transact(Binder.java:503)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at android.app.ApplicationThreadProxy.schedulePauseActivity(ApplicationThreadNative.java:727)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:867)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:2907)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStack.finishTopRunningActivityLocked(ActivityStack.java:2763)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityStackSupervisor.finishTopRunningActivityLocked(ActivityStackSupervisor.java:2755)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:11971)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:11867)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:12556)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:12063)
06-28 15:38:41.924  1545  5075 W ActivityManager:   at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
06-28 15:38:41.929  1545  1564 E JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 60)
06-28 15:38:41.939  1202  1202 I Zygote  : Process 5040 exited due to signal (4)
06-28 15:38:41.939  1545  1583 W InputDispatcher: channel 'd92372c org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
06-28 15:38:41.939  1545  1583 E InputDispatcher: channel 'd92372c org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
06-28 15:38:41.946  1545  1556 D GraphicsStats: Buffer count: 3
06-28 15:38:41.946  1545  1665 I WindowState: WIN DEATH: Window{d92372c u0 org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity}
06-28 15:38:41.946  1545  1665 W InputDispatcher: Attempted to unregister already unregistered input channel 'd92372c org.nativescript.modalmemoryleak/com.tns.NativeScriptActivity (server)'
06-28 15:38:41.958  1189  1449 E SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
06-28 15:38:41.959  1545  5078 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-28 15:38:41.963  1545  1663 I ActivityManager: Process org.nativescript.modalmemoryleak (pid 5040) has died
06-28 15:38:41.998  1545  5078 D         : HostConnection::get() New Host Connection established 0x9e4fc300, tid 5078
06-28 15:38:42.036  1545  5078 I OpenGLRenderer: Initialized EGL, version 1.4
06-28 15:38:42.571  1787  2023 W OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
06-28 15:38:42.677  1545  1564 W WindowAnimator: Failed to dispatch window animation state change.
06-28 15:38:42.677  1545  1564 W WindowAnimator: android.os.DeadObjectException
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.BinderProxy.transactNative(Native Method)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.BinderProxy.transact(Binder.java:503)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.IWindow$Stub$Proxy.onAnimationStopped(IWindow.java:534)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator.updateWindowsLocked(WindowAnimator.java:286)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator.animateLocked(WindowAnimator.java:678)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator.-wrap0(WindowAnimator.java)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.wm.WindowAnimator$1.doFrame(WindowAnimator.java:123)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:856)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer.doFrame(Choreographer.java:603)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.Handler.handleCallback(Handler.java:739)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.Handler.dispatchMessage(Handler.java:95)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.Looper.loop(Looper.java:148)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at android.os.HandlerThread.run(HandlerThread.java:61)
06-28 15:38:42.677  1545  1564 W WindowAnimator:    at com.android.server.ServiceThread.run(ServiceThread.java:46)
@hamorphis

This comment has been minimized.

Show comment
Hide comment
@hamorphis

hamorphis Jun 29, 2016

Contributor

Another way to avoid the memory leak until it is fixed is to use images from App_Resources, i.e. with "res://image1". The built-in Android caching will load the bitmap only once instead of creating a new Bitmap like it would if using images from files.

Contributor

hamorphis commented Jun 29, 2016

Another way to avoid the memory leak until it is fixed is to use images from App_Resources, i.e. with "res://image1". The built-in Android caching will load the bitmap only once instead of creating a new Bitmap like it would if using images from files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment