diff mac/dw.m @ 2816:4521f014bb17

Fix some memory leaks reported by Xcode's Instruments.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 01 Aug 2022 22:46:31 +0000
parents 1efe0ed76629
children 3731f21dd678
line wrap: on
line diff
--- a/mac/dw.m	Mon Aug 01 22:09:46 2022 +0000
+++ b/mac/dw.m	Mon Aug 01 22:46:31 2022 +0000
@@ -3108,7 +3108,7 @@
 }
 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
--(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [scrollview release]; [super dealloc]; }
+-(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [self clear]; [scrollview release]; [super dealloc]; }
 @end
 
 /* Dive into the tree freeing all desired child nodes */
@@ -6398,17 +6398,18 @@
 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, buffer, const char *, startpoint, int)
 {
     DW_FUNCTION_INIT;
+    DW_LOCAL_POOL_IN;
     DWMLE *mle = handle;
     unsigned int retval;
     NSTextStorage *ts = [mle textStorage];
     NSString *nstr = [NSString stringWithUTF8String:buffer];
     NSColor *fgcolor = [ts foregroundColor];
     NSFont *font = [ts font];
-    NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
+    NSMutableDictionary *attributes = [[[NSMutableDictionary alloc] init] autorelease];
     [attributes setObject:(fgcolor ? fgcolor : [NSColor textColor]) forKey:NSForegroundColorAttributeName];
     if(font)
         [attributes setObject:font forKey:NSFontAttributeName];
-    NSAttributedString *nastr = [[NSAttributedString alloc] initWithString:nstr attributes:attributes];
+    NSAttributedString *nastr = [[[NSAttributedString alloc] initWithString:nstr attributes:attributes] autorelease];
     NSUInteger length = [ts length];
     if(startpoint < 0)
         startpoint = 0;
@@ -6416,6 +6417,7 @@
         startpoint = (int)length;
     [ts insertAttributedString:nastr atIndex:startpoint];
     retval = (unsigned int)strlen(buffer) + startpoint;
+    DW_LOCAL_POOL_OUT;
     DW_FUNCTION_RETURN_THIS(retval);
 }