You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/advanced-topics/marking-mode-none.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,6 @@ position: 4
5
5
slug: marking-mode-none
6
6
---
7
7
8
-
> **WARNING**: Use caution when enabling this option and make sure to thoroughly test your apps with different memory constrains and devices! In this mode NativeScript does not take care of the lifetime of Java instances and unexpected and unpredictable crashes can occur due to Java instances being prematurely collected. The errors generated in such cases look like this:
9
-
`Error: com.tns.NativeScriptException: Attempt to use cleared object reference id=<some-object-id-number>`
10
-
... or like:
11
-
`The JavaScript instance no longer has available Java instance counterpart`
12
-
13
-
14
8
# Optimizing Performance Using markingMode: none
15
9
16
10
Starting with NativeScript 3.2, a new (experimental at the time) feature was added to the Android runtime called `markingMode`. Its purpose is to speed up garbage collection in the V8 engine. In some cases, a GC pass could take from 0.5 to 1 second and since it runs on the main UI thread, the user would experience a frozen app until GC is done. Setting “markingMode” to “none” will speed up the garbage collection greatly, so it would be less noticeable (if at all) to the app user. The downside of this approach is that some objects could be collected while their counterparts (in V8 or Android) are still in use. Such case is when JavaScript objects are referenced only from native code and in the eyes of the V8 GC no JS object holds reference to them. In other words – the objects are no longer “marked” as used and the V8 GC might collect them too early.
@@ -33,7 +27,11 @@ First, to instruct any app to use this feature we need to add the following in t
33
27
"markingMode": "none",
34
28
}
35
29
```
36
-
If the app behaves correctly after this change - great. If, however, some sporadic errors occur, especially related to memory management ("Attempt to use cleared object reference" etc), additional work has to be done. Have in mind the problem could be either in the app code, or in some plugin(s) used by the app. In both cases the resolution is identical.
30
+
If the app behaves correctly after this change - great. Sometimes, however, some sporadic errors/crashes occur, especially related to memory management, like any of the following:
31
+
-`Error: com.tns.NativeScriptException: Attempt to use cleared object reference id=<some-object-id-number>`
32
+
-`The JavaScript instance no longer has available Java instance counterpart`
33
+
34
+
In such cases additional work has to be done. Have in mind the problem could be either in the app code, or in some plugin(s) used by the app. In both cases the resolution is identical.
37
35
38
36
### Let’s start with an example
39
37
@@ -47,7 +45,7 @@ var callback = new android.native.NCallback({ // native interface
The implementor is enclosed by the callback implementation, but with `markingMode: none` enabled the framework longer takes care of finding out that connection. So, when GC happens in V8 or in Android the `implementor` instance (or its native representation) is GC'ed. This can result in either Java or JavaScript instance missing and upon calling of the `callback` an "Attempt to use cleared object reference" or "JavaScript instance no longer has available Java counterpart" error is very likely to occur.
48
+
The implementor is enclosed by the callback implementation, but with `markingMode: none` enabled the framework no longer takes care of finding out that connection. So, when GC happens in V8 or in Android the `implementor` instance (or its native representation) is GC'ed. This can result in either Java or JavaScript instance missing and upon calling of the `callback` an "Attempt to use cleared object reference" or "JavaScript instance no longer has available Java counterpart" error is very likely to occur.
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/advanced-topics/memory-management.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,6 @@ position: 4
5
5
slug: memory-management
6
6
---
7
7
8
-
> **NOTE:** This is an experimental feature and some details may change in future.
9
-
10
8
# Memory Management
11
9
12
10
The current implementaion of NativeScript for Android utilizes both V8 and Dalvik/ART garbage collectors. Having two garbage collectors may provide challenges for memory management in some scenarios. This articles describes an experimental feature that allows you better fine control for memory management.
0 commit comments