@@ -325,21 +325,23 @@ void main() {
325
325
await completionPort.first;
326
326
});
327
327
test ('with self delegate' , () async {
328
- final pool = autoreleasePoolPush ();
329
- DartInputStreamAdapter ? inputStream =
330
- Stream .fromIterable ([
331
- [1 , 2 , 3 ],
332
- ]).toNSInputStream ()
333
- as DartInputStreamAdapter ;
334
-
335
- expect (inputStream.delegate, inputStream);
336
-
337
- final ptr = inputStream.ref.pointer;
338
- autoreleasePoolPop (pool);
328
+ late DartInputStreamAdapter ? inputStream;
329
+ late Pointer <ObjCObject > ptr;
330
+ autoReleasePool (() {
331
+ inputStream =
332
+ Stream .fromIterable ([
333
+ [1 , 2 , 3 ],
334
+ ]).toNSInputStream ()
335
+ as DartInputStreamAdapter ;
336
+
337
+ expect (inputStream! .delegate, inputStream);
338
+
339
+ ptr = inputStream! .ref.pointer;
340
+ });
339
341
expect (objectRetainCount (ptr), greaterThan (0 ));
340
342
341
- inputStream.open ();
342
- inputStream.close ();
343
+ inputStream! .open ();
344
+ inputStream! .close ();
343
345
inputStream = null ;
344
346
345
347
doGC ();
@@ -350,22 +352,24 @@ void main() {
350
352
});
351
353
352
354
test ('with non-self delegate' , () async {
353
- final pool = autoreleasePoolPush ();
354
- DartInputStreamAdapter ? inputStream =
355
- Stream .fromIterable ([
356
- [1 , 2 , 3 ],
357
- ]).toNSInputStream ()
358
- as DartInputStreamAdapter ;
359
-
360
- inputStream.delegate = NSStreamDelegate .castFrom (NSObject ());
361
- expect (inputStream.delegate, isNot (inputStream));
362
-
363
- final ptr = inputStream.ref.pointer;
364
- autoreleasePoolPop (pool);
355
+ late DartInputStreamAdapter ? inputStream;
356
+ late Pointer <ObjCObject > ptr;
357
+ autoReleasePool (() {
358
+ inputStream =
359
+ Stream .fromIterable ([
360
+ [1 , 2 , 3 ],
361
+ ]).toNSInputStream ()
362
+ as DartInputStreamAdapter ;
363
+
364
+ inputStream! .delegate = NSStreamDelegate .castFrom (NSObject ());
365
+ expect (inputStream! .delegate, isNot (inputStream));
366
+
367
+ ptr = inputStream! .ref.pointer;
368
+ });
365
369
expect (objectRetainCount (ptr), greaterThan (0 ));
366
370
367
- inputStream.open ();
368
- inputStream.close ();
371
+ inputStream! .open ();
372
+ inputStream! .close ();
369
373
inputStream = null ;
370
374
371
375
doGC ();
0 commit comments