Adds autorelease pools to java.lang.reflect.Method's invoke methods. This reduces overhead running tests using JUnit, which uses reflection extensively.
@@ -78,6 +78,8 @@ static bool IsStatic(const J2ObjcMethodInfo *metadata) {
- (id)invokeWithId:(id)object
withNSObjectArray:(IOSObjectArray *)arguments {
+ id result = nil;
+ @autoreleasepool {
if (!IsStatic(metadata_)) {
if (object == nil) {
@throw AUTORELEASE([[JavaLangNullPointerException alloc] initWithNSString:
@@ -114,12 +116,15 @@ static bool IsStatic(const J2ObjcMethodInfo *metadata) {
}
J2ObjcRawValue returnValue;
[invocation getReturnValue:&returnValue];
- return [returnType __boxValue:&returnValue];
+ result = RETAIN_([returnType __boxValue:&returnValue]);
+ }
+ return AUTORELEASE(result);
}
- (void)jniInvokeWithId:(id)object
args:(const J2ObjcRawValue *)args
result:(J2ObjcRawValue *)result {
+ @autoreleasepool {
NSInvocation *invocation = [self invocationForTarget:object];
for (int i = 0; i < [self getParameterTypesInternal]->size_; i++) {
[invocation setArgument:(void *)&args[i] atIndex:i + SKIPPED_ARGUMENTS];
@@ -131,6 +136,7 @@ static bool IsStatic(const J2ObjcMethodInfo *metadata) {
[invocation getReturnValue:result];
}
}
+}
// Creates a unique method selector by prepending the class name.
static SEL GetPrivatizedMethodSelector(Class cls, SEL sel) {
