mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-02 07:47:25 +07:00
[debugger] use a spare args array element to avoid gc of the evaluation result
GitOrigin-RevId: 5c4e407769780b05a7028cfe3b4e3a40d2f42b05
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4d8090a022
commit
09d8f28ebf
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
/*
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -8,12 +8,16 @@ package com.intellij.rt.debugger;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class BatchEvaluatorServer {
|
||||
/**
|
||||
* Serialize result in one String to avoid multiple getValue commands from the resulting array
|
||||
*/
|
||||
public static String evaluate(Object[] objects) throws IOException {
|
||||
public static String evaluate(Object[] args) throws IOException {
|
||||
// the last element is always null, it is reserved for the return value (to avoid gc collection)
|
||||
Object[] objects = Arrays.copyOf(args, args.length - 1);
|
||||
|
||||
ByteArrayOutputStream bas = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bas);
|
||||
for (Object object : objects) {
|
||||
@@ -33,6 +37,8 @@ public final class BatchEvaluatorServer {
|
||||
dos.writeBoolean(error);
|
||||
dos.writeUTF(res);
|
||||
}
|
||||
return bas.toString("ISO-8859-1");
|
||||
String result = bas.toString("ISO-8859-1");
|
||||
args[args.length - 1] = result; // store the result as the last array element to avoid it being collected
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user