Revision: 28680
http://sourceforge.net/p/bibdesk/svn/28680
Author: hofman
Date: 2024-01-25 23:33:35 +0000 (Thu, 25 Jan 2024)
Log Message:
-----------
Use blocks forr timers with weak references to self to avoid a retain loop
Modified Paths:
--------------
trunk/bibdesk/BDSKCondition.m
trunk/bibdesk/BDSKTypeSelectHelper.m
trunk/bibdesk/BDSKWebView.m
Modified: trunk/bibdesk/BDSKCondition.m
===================================================================
--- trunk/bibdesk/BDSKCondition.m 2024-01-25 23:11:53 UTC (rev 28679)
+++ trunk/bibdesk/BDSKCondition.m 2024-01-25 23:33:35 UTC (rev 28680)
@@ -657,7 +657,7 @@
return [date1 compare:date2] != NSOrderedSame;
}
-- (void)refreshCachedDates:(NSTimer *)timer {
+- (void)refreshCachedDates {
NSDate *startDate = nil;
NSDate *endDate = nil;
BOOL changed = NO;
@@ -683,7 +683,10 @@
- (void)startCacheTimer {
// we fire 1 second past midnight after the end of the current period,
because the condition changes at midnight
NSDate *fireDate = [[NSDate date] startOfPeriod:periodValue byAdding:1
atHour:0 minute:0 second:1];
- cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0
target:self selector:@selector(refreshCachedDates:) userInfo:NULL repeats:NO];
+ __weak BDSKCondition *weakSelf = self;
+ cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0
repeats:NO block:^(NSTimer *timer){
+ [weakSelf refreshCachedDates];
+ }];
[[NSRunLoop currentRunLoop] addTimer:cacheTimer
forMode:NSDefaultRunLoopMode];
}
Modified: trunk/bibdesk/BDSKTypeSelectHelper.m
===================================================================
--- trunk/bibdesk/BDSKTypeSelectHelper.m 2024-01-25 23:11:53 UTC (rev
28679)
+++ trunk/bibdesk/BDSKTypeSelectHelper.m 2024-01-25 23:33:35 UTC (rev
28680)
@@ -249,7 +249,10 @@
- (void)startTimer;
{
[self stopTimer];
- timer = [[NSTimer alloc] initWithFireDate:[NSDate
dateWithTimeIntervalSinceNow:[self timeoutInterval]] interval:0 target:self
selector:@selector(typeSelectSearchTimeout:) userInfo:NULL repeats:NO];
+ __weak BDSKTypeSelectHelper *weakSelf = self;
+ timer = [[NSTimer alloc] initWithFireDate:[NSDate
dateWithTimeIntervalSinceNow:[self timeoutInterval]] interval:0 repeats:NO
block:^(NSTimer *timer){
+ [weakSelf typeSelectSearchTimeout:nil];
+ }];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}
Modified: trunk/bibdesk/BDSKWebView.m
===================================================================
--- trunk/bibdesk/BDSKWebView.m 2024-01-25 23:11:53 UTC (rev 28679)
+++ trunk/bibdesk/BDSKWebView.m 2024-01-25 23:33:35 UTC (rev 28680)
@@ -349,7 +349,16 @@
- (void)monitorURL {
[self stopMonitoringURL];
- urlTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self
selector:@selector(urlTimerFired:) userInfo:[self mainFrameURL] repeats:YES];
+ __weak BDSKWebView *weakSelf = self;
+ NSString *mainFrameURL = [self mainFrameURL];
+ urlTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES
block:^(NSTimer *timer){
+ if (weakSelf && [[weakSelf mainFrameURL] isEqualToString:mainFrameURL]
== NO) {
+ WebFrame *frame = [weakSelf mainFrame];
+ [webDelegate webView:weakSelf
didStartProvisionalLoadForFrame:frame];
+ [webDelegate webView:weakSelf didCommitLoadForFrame:frame];
+ [webDelegate webView:weakSelf didFinishLoadForFrame:frame];
+ }
+ }];
}
@end
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