Skip to content

Commit 5575797

Browse files
author
nce40202
committed
fix: 移除无效的对象大小检查并添加堆空间溢出异常
移除 `isValidObject` 计算属性中无效的对象大小检查,并在创建对象时添加堆空间溢出异常处理,以防止对象大小超过堆空间时程序继续执行。
1 parent 836164c commit 5575797

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/views/MemoryVisualizer.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,8 @@ const convertToBytes = (size: number, unit: string) => {
434434
const hasApplicationError = ref(false);
435435
436436
const isValidObject = computed(() => {
437-
const sizeInBytes = convertToBytes(newObject.value.size, newObject.value.unit);
438437
return newObject.value.name &&
439438
newObject.value.size > 0 &&
440-
sizeInBytes <= (heapSize.value - usedHeapSize.value) &&
441439
!hasApplicationError.value;
442440
});
443441
@@ -626,6 +624,11 @@ const createObject = () => {
626624
isGarbageCollectable: newObject.value.isGarbageCollectable
627625
} as HeapObject;
628626
627+
// 对象大小超过堆空间大小,直接抛出异常
628+
if (sizeInBytes > heapSize.value) {
629+
throw applicationError('java.lang.OutOfMemoryError: Java heap space');
630+
}
631+
629632
if (sizeInBytes >= memoryConfig.value.pretenureSizeThreshold && memoryConfig.value.pretenureSizeThreshold > 0) {
630633
// 对象大小超过阈值,直接进入Old Gen区
631634
if (getSpaceUsed(MEMORY_SPACE.OLD_GEN) + newObj.size > oldGenSize.value) {

0 commit comments

Comments
 (0)