Skip to content

Commit 143a0f7

Browse files
committed
[generator] Use GC.KeepAlive for reference type method parameters.
1 parent a807961 commit 143a0f7

32 files changed

+81
-0
lines changed

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public partial class MyClass {
162162
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
163163
} finally {
164164
JNIEnv.DeleteLocalRef (native_value);
165+
global::System.GC.KeepAlive (value);
165166
}
166167
}
167168
}
@@ -260,6 +261,7 @@ public partial class MyClass {
260261
return __rm;
261262
} finally {
262263
JNIEnv.DeleteLocalRef (native_key);
264+
global::System.GC.KeepAlive (key);
263265
}
264266
}
265267

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public virtual unsafe int GetCountForKey (string key)
2929
return __rm;
3030
} finally {
3131
JNIEnv.DeleteLocalRef (native_key);
32+
global::System.GC.KeepAlive (key);
3233
}
3334
}
3435

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassProperties.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public virtual unsafe string Key {
109109
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
110110
} finally {
111111
JNIEnv.DeleteLocalRef (native_value);
112+
global::System.GC.KeepAlive (value);
112113
}
113114
}
114115
}

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypeMethodsClass.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public partial class MyClass {
2727
JNIEnv.CopyArray (native_value, value);
2828
JNIEnv.DeleteLocalRef (native_value);
2929
}
30+
global::System.GC.KeepAlive (value);
3031
}
3132
}
3233

@@ -46,6 +47,7 @@ public partial class MyClass {
4647
JNIEnv.CopyArray (native_value, value);
4748
JNIEnv.DeleteLocalRef (native_value);
4849
}
50+
global::System.GC.KeepAlive (value);
4951
}
5052
}
5153

@@ -65,6 +67,7 @@ public partial class MyClass {
6567
JNIEnv.CopyArray (native_value, value);
6668
JNIEnv.DeleteLocalRef (native_value);
6769
}
70+
global::System.GC.KeepAlive (value);
6871
}
6972
}
7073

@@ -84,6 +87,7 @@ public partial class MyClass {
8487
JNIEnv.CopyArray (native_value, value);
8588
JNIEnv.DeleteLocalRef (native_value);
8689
}
90+
global::System.GC.KeepAlive (value);
8791
}
8892
}
8993

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypePropertiesClass.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public partial class MyClass {
3636
JNIEnv.CopyArray (native_value, value);
3737
JNIEnv.DeleteLocalRef (native_value);
3838
}
39+
global::System.GC.KeepAlive (value);
3940
}
4041
}
4142
}
@@ -65,6 +66,7 @@ public partial class MyClass {
6566
JNIEnv.CopyArray (native_value, value);
6667
JNIEnv.DeleteLocalRef (native_value);
6768
}
69+
global::System.GC.KeepAlive (value);
6870
}
6971
}
7072
}
@@ -94,6 +96,7 @@ public partial class MyClass {
9496
JNIEnv.CopyArray (native_value, value);
9597
JNIEnv.DeleteLocalRef (native_value);
9698
}
99+
global::System.GC.KeepAlive (value);
97100
}
98101
}
99102
}
@@ -123,6 +126,7 @@ public partial class MyClass {
123126
JNIEnv.CopyArray (native_value, value);
124127
JNIEnv.DeleteLocalRef (native_value);
125128
}
129+
global::System.GC.KeepAlive (value);
126130
}
127131
}
128132
}

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypePropertiesClass.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public partial class MyClass {
103103
__args [0] = new JniArgumentValue (value);
104104
_members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args);
105105
} finally {
106+
global::System.GC.KeepAlive (value);
106107
}
107108
}
108109
}

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public partial class MyClass {
162162
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
163163
} finally {
164164
JNIEnv.DeleteLocalRef (native_value);
165+
global::System.GC.KeepAlive (value);
165166
}
166167
}
167168
}
@@ -260,6 +261,7 @@ public partial class MyClass {
260261
return __rm;
261262
} finally {
262263
JNIEnv.DeleteLocalRef (native_key);
264+
global::System.GC.KeepAlive (key);
263265
}
264266
}
265267

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public virtual unsafe int GetCountForKey (string? key)
2929
return __rm;
3030
} finally {
3131
JNIEnv.DeleteLocalRef (native_key);
32+
global::System.GC.KeepAlive (key);
3233
}
3334
}
3435

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassProperties.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public virtual unsafe string? Key {
109109
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
110110
} finally {
111111
JNIEnv.DeleteLocalRef (native_value);
112+
global::System.GC.KeepAlive (value);
112113
}
113114
}
114115
}

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClass.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public partial class MyClass {
162162
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
163163
} finally {
164164
JNIEnv.DeleteLocalRef (native_value);
165+
global::System.GC.KeepAlive (value);
165166
}
166167
}
167168
}
@@ -260,6 +261,7 @@ public partial class MyClass {
260261
return __rm;
261262
} finally {
262263
JNIEnv.DeleteLocalRef (native_key);
264+
global::System.GC.KeepAlive (key);
263265
}
264266
}
265267

0 commit comments

Comments
 (0)