File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -41,10 +41,18 @@ Future testWeakReferenceWeakness() async {
4141    foo =  null ;
4242  }
4343  asyncStart ();
44-   while  (weakReference.target !=  null ) {
44+   // According to the WeakReference specification: 
45+   // 
46+   // There are no guarantees that a weak reference will ever be cleared 
47+   // even if all references to its target are weak references. 
48+   // 
49+   // Wait a few iterations and give up if target is not cleared. 
50+   const  int  numIterations =  10 ;
51+   int  i =  0 ;
52+   for  (; weakReference.target !=  null  &&  i <  numIterations; ++ i) {
4553    produceGarbage ();
4654    await  Future .delayed (const  Duration (milliseconds:  10 ));
4755  }
48-   Expect .isNull ( weakReference.target);
56+   Expect .isTrue (i  ==  numIterations  ||   weakReference.target  ==   null );
4957  asyncEnd ();
5058}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments