ios-jsc icon indicating copy to clipboard operation
ios-jsc copied to clipboard

Help Wanted: How to correctly dealloc TNSRuntime?

Open kosekmi opened this issue 7 years ago • 0 comments

Hi,

i'm trying to dealloc an instance of TNSRuntime while JS is executed. If TNSRuntime is set to nil or the context is released the App crashes with EXC_BAD_ACCESS.

Example Code is provided below - any help is appreciated

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

  • CLI: 4.1.1
  • Cross-platform modules: 4.1.0
  • Plugin(s): -

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

[See Code Below]

  1. Setup TNSRuntime
  2. Execute JS
  3. Dealloc or Release Context

Is there any code involved?

Setup TNSRuntime:

extern char startOfMetadataSection __asm("section$start$__DATA$__TNSMetadata");
[TNSRuntime initializeMetadata:&startOfMetadataSection];
TNSRuntime *tnsRuntime = [[TNSRuntime alloc] initWithApplicationPath:[[NSBundle mainBundle] bundlePath]];

Execute JS:

JSValueRef error = nil;
JSStringRef script = JSStringCreateWithCFString((__bridge CFStringRef)(source));
JSEvaluateScript(tnsRuntime.globalContext, @"require('globals');setInterval(function(){console.log('Hello World');}, 500);", nil, nil, 0, &error);
JSStringRelease(script);

Dealloc: tnsRuntime = nil; Release Context: JSGlobalContextRelease(tnsRuntime.globalContext);

kosekmi avatar Jun 22 '18 14:06 kosekmi