Revision: 28563
          http://sourceforge.net/p/bibdesk/svn/28563
Author:   hofman
Date:     2024-01-06 18:27:38 +0000 (Sat, 06 Jan 2024)
Log Message:
-----------
Avoid retain cycle for recursive block by using a weak block variable inside 
the block, passed to a strong variable when passed on to an async block

Modified Paths:
--------------
    trunk/bibdesk/BDSKFiler.m

Modified: trunk/bibdesk/BDSKFiler.m
===================================================================
--- trunk/bibdesk/BDSKFiler.m   2024-01-06 18:18:26 UTC (rev 28562)
+++ trunk/bibdesk/BDSKFiler.m   2024-01-06 18:27:38 UTC (rev 28563)
@@ -176,6 +176,7 @@
         [[self window] orderFront:nil];
        }
        
+    __weak __block void (^weakFilePaperInfo)(NSInteger);
     __block void (^filePaperInfo)(NSInteger) = [^(NSInteger i){
         
         if (i < numberOfPapers) {
@@ -244,6 +245,8 @@
                     
                 } else {
                     
+                    void (^strongFilePaperInfo)(NSInteger) = weakFilePaperInfo;
+                    
                     [doc runScriptHookWithName:BDSKScriptHookNameWillAutoFile
                         forPublications:@[pub]
                         field:field oldValues:@[oldPath] newValues:@[newPath]
@@ -286,7 +289,7 @@
                             [pub removeFileToBeFiled:file];
                         
                         // file the next one, or finish
-                        filePaperInfo(i + 1);
+                        strongFilePaperInfo(i + 1);
                     }];
                     // filing the next one is done in the completion handler
                     return;
@@ -294,7 +297,7 @@
             }
             
             // file the next one, or finish
-            filePaperInfo(i + 1);
+            weakFilePaperInfo(i + 1);
 
         } else {
             // we've exhauster the paperInfos array, finish up
@@ -329,10 +332,11 @@
             [self runPendingFilingIfNeeded];
             
             // this balances the copy, avoids a retain cycle
-            BDSKDESTROY(filePaperInfo);
+            BDSKDESTROY(weakFilePaperInfo);
         }
     } copy];
-       
+    weakFilePaperInfo = filePaperInfo;
+    
     // file the first paper, this will recursively call the next one
     filePaperInfo(0);
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to