1/** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 17let test2021_05_ans = ""; 18 19interface weakRefObj { 20 id: number 21 ref: undefined | WeakRef<weakRefObj> 22}; 23let obj1: weakRefObj | null = { id: 1, ref: undefined }; 24let obj2: weakRefObj | null = { id: 2, ref: undefined }; 25let weakRef1: WeakRef<weakRefObj> = new WeakRef(obj2); 26let weakRef2: WeakRef<weakRefObj> = new WeakRef(obj1); 27obj1.ref = weakRef1; 28obj2.ref = weakRef2; 29 30obj1 = null; 31obj2 = null; 32test2021_05_ans += weakRef1.deref()?.id 33test2021_05_ans += weakRef2.deref()?.id 34setTimeout(() => { 35 //@ts-ignore 36 ArkTools.forceFullGC(); 37 setTimeout(() => { 38 if (weakRef1.deref()?.id) { 39 test2021_05_ans += weakRef1.deref()?.id 40 } 41 if (weakRef2.deref()?.id) { 42 test2021_05_ans += weakRef2.deref()?.id 43 } 44 }, 100); 45}, 100); 46 47export { test2021_05_ans }