[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:45:55 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 123e3e88001244f77834531d6f029c878fde9a89
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jun 15 05:55:27 2004 +0000

            Reviewed by me, code changes by Patrick Beard.
    
            - fixed <rdar://problem/3671507>: (WebKit should adopt GC changes and compile with GC enabled)
    
            * WebKit.pbproj/project.pbxproj: Added WebNSObjectExtras.h.
            * Misc.subproj/WebNSObjectExtras.h: Added. Includes WebMakeCollectable, a cover for
            CFMakeCollectable that returns type id, for less casting, and works on Panther as well
            as Tiger. Also declares finalize in NSObject so we can call super without warnings on Panther.
    
            * Carbon.subproj/CarbonWindowAdapter.m: Fixed header and includes a bit.
            (-[CarbonWindowAdapter finalize]): Added.
            * History.subproj/WebBackForwardList.m:
            (-[WebBackForwardList dealloc]): Got count outside loop.
            (-[WebBackForwardList finalize]): Added.
            * History.subproj/WebHistoryItem.m:
            (-[WebHistoryItem finalize]): Added.
            * Misc.subproj/WebFileDatabase.m:
            (-[WebFileDatabase _createLRUList:]): Use release on Panther, drain on Tiger.
            (+[WebFileDatabase _syncLoop:]): Ditto.
            (-[WebFileDatabase dealloc]): Removed, since we never deallocate objects of this class, and
            the method was untested.
            * Misc.subproj/WebKitErrors.m: (registerErrors): Use release on Panther, drain on Tiger.
            * Misc.subproj/WebKitNSStringExtras.m: (+[NSString _web_encodingForResource:]): Use
            WebMakeCollectable. Also fixed indenting.
            * Misc.subproj/WebNSURLExtras.m:
            (+[NSURL _web_URLWithData:relativeToURL:]): Use WebMakeCollectable.
            (-[NSURL _web_URLWithLowercasedScheme]): Use WebMakeCollectable.
            (-[NSString _web_mapHostNameWithRange:encode:makeString:]): Change code to use CFRelease
            to balance CFURLCreateStringByReplacingPercentEscapes CFString creation, not release.
            * Plugins.subproj/WebBaseNetscapePluginStream.m:
            (-[WebBaseNetscapePluginStream finalize]): Added.
            * Plugins.subproj/WebBaseNetscapePluginView.m:
            (-[WebBaseNetscapePluginView freeAttributeKeysAndValues]): Added. Shared code for dealloc and finalize.
            (-[WebBaseNetscapePluginView dealloc]): Call freeAttributeKeysAndValues.
            (-[WebBaseNetscapePluginView finalize]): Added.
            (-[WebBaseNetscapePluginView requestWithURLCString:]): Changed so that CFString objects are
            released with CFRelease, not release.
            (-[WebBaseNetscapePluginView loadRequest:inTarget:withNotifyData:]): Fixed storage leak in
            error case. Made sure CFString object is released with CFRelease, not release.
            (-[WebBaseNetscapePluginView _postURLNotify:target:len:buf:file:notifyData:allowHeaders:]):
            Another CFString that needed to a CFRelease, not a release.
            (-[WebBaseNetscapePluginView status:]): Ditto.
            * Plugins.subproj/WebBasePluginPackage.m:
            (-[WebBasePluginPackage pathByResolvingSymlinksAndAliasesInPath:]): Changed code to
            CFRelease a CFURLRef, instead of release.
            (-[WebBasePluginPackage finalize]): Added.
            * WebCoreSupport.subproj/WebBridge.m:
            (-[WebBridge fini]): Added. Shared code for dealloc and finalize.
            (-[WebBridge dealloc]): Call fini.
            (-[WebBridge finalize]): Added.
            * WebCoreSupport.subproj/WebGlyphBuffer.m:
            (-[WebGlyphBuffer finalize]): Added.
            * WebCoreSupport.subproj/WebImageRenderer.m:
            (-[WebImageContext initWithBounds:context:]): Use CGContextRetain to avoid cast.
            (-[WebImageContext dealloc]): Tweaked.
            (-[WebImageContext finalize]): Added.
            (-[WebImageRenderer finalize]): Added.
            (-[WebPDFDocument finalize]): Added.
            * WebView.subproj/WebDataProtocol.m:
            (+[NSURL _web_uniqueWebDataURL]): Changed so that CFString object is released with
            CFRelease, not release.
            * WebView.subproj/WebDataSource.m:
            (-[WebDataSourcePrivate dealloc]): Took non-release work out of here.
            (-[WebDataSource dealloc]): Moved it here.
            (-[WebDataSource finalize]): Added.
            (-[WebDataSource isLoading]): Use release on Panther, drain on Tiger.
            * WebView.subproj/WebFrame.m:
            (-[WebFramePrivate dealloc]): Took non-release work out of here.
            (-[WebFrame dealloc]): Moved it here.
            (-[WebFrame finalize]): Added.
            * WebView.subproj/WebFrameView.m:
            (-[WebFrameView finalize]): Added.
            * WebView.subproj/WebHTMLRepresentation.m:
            (-[WebHTMLRepresentation finalize]): Added.
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLViewPrivate dealloc]): Moved non-release work out of here.
            (-[WebHTMLView dealloc]): Moved it here.
            (-[WebHTMLView finalize]): Added.
            * WebView.subproj/WebImageView.m:
            (-[WebImageView finalize]): Added.
            * WebView.subproj/WebMainResourceClient.m:
            (-[WebMainResourceClient finalize]): Added.
            * WebView.subproj/WebTextView.m:
            (-[WebTextView finalize]): Added.
            * WebView.subproj/WebView.m:
            (-[WebView finalize]): Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6839 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/Carbon.subproj/CarbonWindowAdapter.m b/WebKit/Carbon.subproj/CarbonWindowAdapter.m
index 8e75295..cc5abad 100644
--- a/WebKit/Carbon.subproj/CarbonWindowAdapter.m
+++ b/WebKit/Carbon.subproj/CarbonWindowAdapter.m
@@ -3,7 +3,7 @@
 //  Synergy
 //
 //  Created by Ed Voas on Fri Jan 17 2003.
-//  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
+//  Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
 //
 
 /*
@@ -54,6 +54,7 @@ The subclass of NSWindow that encapsulates a Carbon window, in such a manner tha
 #import "HIViewAdapter.h"
 
 #import <AppKit/AppKit.h>
+#import <AppKit/NSWindow_Private.h>
 #import <CoreGraphics/CGSWindow.h>
 #import <HIToolbox/CarbonEvents.h>
 #import <HIToolbox/CarbonEventsPriv.h>
@@ -63,15 +64,7 @@ The subclass of NSWindow that encapsulates a Carbon window, in such a manner tha
 #import <HIToolbox/HIView.h>
 #import <assert.h>
 
-// Turn off the assertions in this file.
-// If this is commented out, uncomment it before committing to CVS.  M.P. Warning - 10/18/01
-#undef assert
-#define assert(X)
-
-enum
-{
-	_NSCarbonWindowMask               = 1 << 25
-};
+#import "WebNSObjectExtras.h"
 
 // Carbon SPI functions.
 // The fact that these are declared here instead of in an HIToolbox header is a bad thing.  2776459.  M.P. To Do - 9/18/01
@@ -83,15 +76,9 @@ OSStatus SyncWindowToCGSWindow(WindowRef inWindow, CGSWindowID inWindowID);
 #define WINDOWSMENUWINDOW(w)   (!_wFlags.excludedFromWindowsMenu && \
                                 [w _miniaturizedOrCanBecomeMain] && [w _isDocWindow])
 extern float _NXScreenMaxYForRect(NSRect *rect);
-extern MenuRef _NSGetCarbonMenu(NSMenu* menu);
-extern int _NSMenuToCarbonIndex(NSMenu* menu, int index);
 extern void _NXOrderKeyAndMain( void );
 extern void _NXShowKeyAndMain( void );
 
-// Forward declarations.
-static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCallRef, EventRef inEventRef, void *inUserData);
-
-
 // Constants that we use to fiddle with NSViewCarbonControls.
 extern const ControlFocusPart NSViewCarbonControlMagicPartCode;
 extern const OSType NSAppKitPropertyCreator;
@@ -119,6 +106,9 @@ extern const OSType NSCarbonWindowPropertyTag;
 - (BOOL)processInputKeyBindings:(NSEvent *)event;
 @end
 
+// Forward declarations.
+static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCallRef, EventRef inEventRef, void *inUserData);
+
 @implementation CarbonWindowAdapter
 
 
@@ -302,6 +292,11 @@ extern const OSType NSCarbonWindowPropertyTag;
 
 }
 
+- (void)finalize {
+    if (_eventHandler) RemoveEventHandler(_eventHandler);
+    [super finalize];
+}
+
 - (WindowRef)windowRef {
 
     // Simple.
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 079dab4..9e96545 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,92 @@
+2004-06-14  Darin Adler  <darin at apple.com>
+
+        Reviewed by me, code changes by Patrick Beard.
+
+        - fixed <rdar://problem/3671507>: (WebKit should adopt GC changes and compile with GC enabled)
+
+        * WebKit.pbproj/project.pbxproj: Added WebNSObjectExtras.h.
+        * Misc.subproj/WebNSObjectExtras.h: Added. Includes WebMakeCollectable, a cover for
+        CFMakeCollectable that returns type id, for less casting, and works on Panther as well
+        as Tiger. Also declares finalize in NSObject so we can call super without warnings on Panther.
+
+        * Carbon.subproj/CarbonWindowAdapter.m: Fixed header and includes a bit.
+        (-[CarbonWindowAdapter finalize]): Added.
+        * History.subproj/WebBackForwardList.m:
+        (-[WebBackForwardList dealloc]): Got count outside loop.
+        (-[WebBackForwardList finalize]): Added.
+        * History.subproj/WebHistoryItem.m:
+        (-[WebHistoryItem finalize]): Added.
+        * Misc.subproj/WebFileDatabase.m:
+        (-[WebFileDatabase _createLRUList:]): Use release on Panther, drain on Tiger.
+        (+[WebFileDatabase _syncLoop:]): Ditto.
+        (-[WebFileDatabase dealloc]): Removed, since we never deallocate objects of this class, and
+        the method was untested.
+        * Misc.subproj/WebKitErrors.m: (registerErrors): Use release on Panther, drain on Tiger.
+        * Misc.subproj/WebKitNSStringExtras.m: (+[NSString _web_encodingForResource:]): Use
+        WebMakeCollectable. Also fixed indenting.
+        * Misc.subproj/WebNSURLExtras.m:
+        (+[NSURL _web_URLWithData:relativeToURL:]): Use WebMakeCollectable.
+        (-[NSURL _web_URLWithLowercasedScheme]): Use WebMakeCollectable.
+        (-[NSString _web_mapHostNameWithRange:encode:makeString:]): Change code to use CFRelease
+        to balance CFURLCreateStringByReplacingPercentEscapes CFString creation, not release.
+        * Plugins.subproj/WebBaseNetscapePluginStream.m:
+        (-[WebBaseNetscapePluginStream finalize]): Added.
+        * Plugins.subproj/WebBaseNetscapePluginView.m:
+        (-[WebBaseNetscapePluginView freeAttributeKeysAndValues]): Added. Shared code for dealloc and finalize.
+        (-[WebBaseNetscapePluginView dealloc]): Call freeAttributeKeysAndValues.
+        (-[WebBaseNetscapePluginView finalize]): Added.
+        (-[WebBaseNetscapePluginView requestWithURLCString:]): Changed so that CFString objects are
+        released with CFRelease, not release.
+        (-[WebBaseNetscapePluginView loadRequest:inTarget:withNotifyData:]): Fixed storage leak in
+        error case. Made sure CFString object is released with CFRelease, not release.
+        (-[WebBaseNetscapePluginView _postURLNotify:target:len:buf:file:notifyData:allowHeaders:]):
+        Another CFString that needed to a CFRelease, not a release.
+        (-[WebBaseNetscapePluginView status:]): Ditto.
+        * Plugins.subproj/WebBasePluginPackage.m:
+        (-[WebBasePluginPackage pathByResolvingSymlinksAndAliasesInPath:]): Changed code to
+        CFRelease a CFURLRef, instead of release.
+        (-[WebBasePluginPackage finalize]): Added.
+        * WebCoreSupport.subproj/WebBridge.m:
+        (-[WebBridge fini]): Added. Shared code for dealloc and finalize.
+        (-[WebBridge dealloc]): Call fini.
+        (-[WebBridge finalize]): Added.
+        * WebCoreSupport.subproj/WebGlyphBuffer.m:
+        (-[WebGlyphBuffer finalize]): Added.
+        * WebCoreSupport.subproj/WebImageRenderer.m:
+        (-[WebImageContext initWithBounds:context:]): Use CGContextRetain to avoid cast.
+        (-[WebImageContext dealloc]): Tweaked.
+        (-[WebImageContext finalize]): Added.
+        (-[WebImageRenderer finalize]): Added.
+        (-[WebPDFDocument finalize]): Added.
+        * WebView.subproj/WebDataProtocol.m:
+        (+[NSURL _web_uniqueWebDataURL]): Changed so that CFString object is released with
+        CFRelease, not release.
+        * WebView.subproj/WebDataSource.m:
+        (-[WebDataSourcePrivate dealloc]): Took non-release work out of here.
+        (-[WebDataSource dealloc]): Moved it here.
+        (-[WebDataSource finalize]): Added.
+        (-[WebDataSource isLoading]): Use release on Panther, drain on Tiger.
+        * WebView.subproj/WebFrame.m:
+        (-[WebFramePrivate dealloc]): Took non-release work out of here.
+        (-[WebFrame dealloc]): Moved it here.
+        (-[WebFrame finalize]): Added.
+        * WebView.subproj/WebFrameView.m:
+        (-[WebFrameView finalize]): Added.
+        * WebView.subproj/WebHTMLRepresentation.m:
+        (-[WebHTMLRepresentation finalize]): Added.
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLViewPrivate dealloc]): Moved non-release work out of here.
+        (-[WebHTMLView dealloc]): Moved it here.
+        (-[WebHTMLView finalize]): Added.
+        * WebView.subproj/WebImageView.m:
+        (-[WebImageView finalize]): Added.
+        * WebView.subproj/WebMainResourceClient.m:
+        (-[WebMainResourceClient finalize]): Added.
+        * WebView.subproj/WebTextView.m:
+        (-[WebTextView finalize]): Added.
+        * WebView.subproj/WebView.m:
+        (-[WebView finalize]): Added.
+
 2004-06-14  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by Darin
diff --git a/WebKit/History.subproj/WebBackForwardList.m b/WebKit/History.subproj/WebBackForwardList.m
index 346c676..b9cac1f 100644
--- a/WebKit/History.subproj/WebBackForwardList.m
+++ b/WebKit/History.subproj/WebBackForwardList.m
@@ -6,6 +6,7 @@
 #import <WebKit/WebBackForwardList.h>
 #import <WebKit/WebHistoryItemPrivate.h>
 #import <WebKit/WebKitLogging.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebPreferencesPrivate.h>
 #import <WebKit/WebKitSystemBits.h>
 
@@ -52,8 +53,9 @@
 
 - (void)dealloc
 {
+    unsigned count = [_private->entries count];
     unsigned i;
-    for (i = 0; i < [_private->entries count]; i++){
+    for (i = 0; i < count; i++){
         WebHistoryItem *item = [_private->entries objectAtIndex: i];
         [item setHasPageCache: NO]; 
     }
@@ -61,6 +63,20 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    // FIXME: This code is incorrect.
+    // Instead, change the design so that the list is already empty when released,
+    // remove the setHasPageCache: code from dealloc, and remove this finalize method.
+    unsigned count = [_private->entries count];
+    unsigned i;
+    for (i = 0; i < count; i++){
+        WebHistoryItem *item = [_private->entries objectAtIndex: i];
+        [item setHasPageCache: NO]; 
+    }
+    [super finalize];
+}
+
 - (void)addItem:(WebHistoryItem *)entry;
 {
     if (_private->maximumSize == 0)
diff --git a/WebKit/History.subproj/WebHistoryItem.m b/WebKit/History.subproj/WebHistoryItem.m
index f328b74..8b8605a 100644
--- a/WebKit/History.subproj/WebHistoryItem.m
+++ b/WebKit/History.subproj/WebHistoryItem.m
@@ -5,16 +5,17 @@
 
 #import <WebKit/WebHistoryItemPrivate.h>
 
+#import <WebKit/WebAssertions.h>
 #import <WebKit/WebFramePrivate.h>
 #import <WebKit/WebFrameView.h>
 #import <WebKit/WebHTMLViewPrivate.h>
 #import <WebKit/WebIconDatabase.h>
 #import <WebKit/WebIconLoader.h>
 #import <WebKit/WebKitLogging.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebPluginController.h>
 
-#import <WebKit/WebAssertions.h>
 #import <Foundation/NSDictionary_NSURLExtras.h>
 
 #import <CoreGraphics/CoreGraphicsPrivate.h>
@@ -108,6 +109,15 @@ NSString *WebHistoryItemChangedNotification = @"WebHistoryItemChangedNotificatio
     [super dealloc];
 }
 
+- (void)finalize
+{
+    // FIXME: Probably not good to release icons from the database only
+    // when the object is garbage-collected. Need to change design so
+    // this happens at a predictable time.
+    [self _retainIconInDatabase:NO];
+    [super finalize];
+}
+
 - (id)copyWithZone:(NSZone *)zone
 {
     WebHistoryItem *copy = NSCopyObject(self, 0, zone);
diff --git a/WebKit/Misc.subproj/WebFileDatabase.m b/WebKit/Misc.subproj/WebFileDatabase.m
index c8641e9..0546d9f 100644
--- a/WebKit/Misc.subproj/WebFileDatabase.m
+++ b/WebKit/Misc.subproj/WebFileDatabase.m
@@ -208,7 +208,11 @@ static void UniqueFilePathForKey(id key, char *buffer)
 
     LOG(FileDatabaseActivity, "lru list created");
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
     [pool release];
+#else
+    [pool drain];
+#endif
 }
 
 -(void)_truncateToSizeLimit:(unsigned)size
@@ -272,7 +276,11 @@ static void UniqueFilePathForKey(id key, char *buffer)
 
     END_EXCEPTION_HANDLER
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
     [pool release];
+#else
+    [pool drain];
+#endif
 }
 
 static void databaseInit()
@@ -306,21 +314,7 @@ static void databaseInit()
     return self;
 }
 
--(void)dealloc
-{
-    [mutex lock];
-    // this locking gives time for writes that are happening now to finish
-    [mutex unlock];
-    [self close];
-    [timer invalidate];
-    [timer release];
-    [ops release];
-    [setCache release];
-    [removeCache release];
-    [mutex release];
-
-    [super dealloc];
-}
+// WebFileDatabase objects are never released, so we need no dealloc implementation.
 
 -(void)setTimer
 {
diff --git a/WebKit/Misc.subproj/WebKitErrors.m b/WebKit/Misc.subproj/WebKitErrors.m
index 62ee45d..8ba9df5 100644
--- a/WebKit/Misc.subproj/WebKitErrors.m
+++ b/WebKit/Misc.subproj/WebKitErrors.m
@@ -122,5 +122,9 @@ static void registerErrors()
 
     [NSError _web_addErrorsWithCodesAndDescriptions:dict inDomain:WebKitErrorDomain];
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
     [pool release];
+#else
+    [pool drain];
+#endif
 }
diff --git a/WebKit/Misc.subproj/WebKitNSStringExtras.m b/WebKit/Misc.subproj/WebKitNSStringExtras.m
index 7f2a8a4..9c7e531 100644
--- a/WebKit/Misc.subproj/WebKitNSStringExtras.m
+++ b/WebKit/Misc.subproj/WebKitNSStringExtras.m
@@ -5,6 +5,7 @@
 
 #import "WebKitNSStringExtras.h"
 
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebTextRenderer.h>
 #import <WebKit/WebTextRendererFactory.h>
 
@@ -133,53 +134,53 @@ static BOOL canUseFastRenderer (const UniChar *buffer, unsigned length)
 
 + (NSStringEncoding)_web_encodingForResource:(Handle)resource
 {
-	short resRef = HomeResFile(resource);
-	if (ResError() != noErr) {
-		return NSMacOSRomanStringEncoding;
-	}
-	
-	// Get the FSRef for the current resource file
-	FSRef fref;
-	OSStatus error = FSGetForkCBInfo(resRef, 0, NULL, NULL, NULL, &fref, NULL);
-	if (error != noErr) {
-		return NSMacOSRomanStringEncoding;
-	}
-	
-	CFURLRef URL = CFURLCreateFromFSRef(NULL, &fref);
-	if (URL == NULL) {
-		return NSMacOSRomanStringEncoding;
-	}
-	
-	NSString *path = [(NSURL *)URL path];
-	CFRelease(URL);
-	
-	// Get the lproj directory name
-	path = [path stringByDeletingLastPathComponent];
-	if (![[path pathExtension] _web_isCaseInsensitiveEqualToString:@"lproj"]) {
-		return NSMacOSRomanStringEncoding;
-	}
-	
-	NSString *directoryName = [[path stringByDeletingPathExtension] lastPathComponent];
-	NSString *locale = (NSString *)CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName);
-	if (locale == nil) {
-		return NSMacOSRomanStringEncoding;
-	}
-		
-	LangCode lang;
-	RegionCode region;
-	error = LocaleStringToLangAndRegionCodes([locale UTF8String], &lang, &region);
-	[locale release];
-	if (error != noErr) {
-		return NSMacOSRomanStringEncoding;
-	}
-	
-	TextEncoding encoding;
-	error = UpgradeScriptInfoToTextEncoding(kTextScriptDontCare, lang, region, NULL, &encoding);
-	if (error != noErr) {
-		return NSMacOSRomanStringEncoding;
-	}
-	
-	return CFStringConvertEncodingToNSStringEncoding(encoding);
+    short resRef = HomeResFile(resource);
+    if (ResError() != noErr) {
+        return NSMacOSRomanStringEncoding;
+    }
+    
+    // Get the FSRef for the current resource file
+    FSRef fref;
+    OSStatus error = FSGetForkCBInfo(resRef, 0, NULL, NULL, NULL, &fref, NULL);
+    if (error != noErr) {
+        return NSMacOSRomanStringEncoding;
+    }
+    
+    CFURLRef URL = CFURLCreateFromFSRef(NULL, &fref);
+    if (URL == NULL) {
+        return NSMacOSRomanStringEncoding;
+    }
+    
+    NSString *path = [(NSURL *)URL path];
+    CFRelease(URL);
+    
+    // Get the lproj directory name
+    path = [path stringByDeletingLastPathComponent];
+    if (![[path pathExtension] _web_isCaseInsensitiveEqualToString:@"lproj"]) {
+        return NSMacOSRomanStringEncoding;
+    }
+    
+    NSString *directoryName = [[path stringByDeletingPathExtension] lastPathComponent];
+    NSString *locale = WebMakeCollectable(CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName));
+    if (locale == nil) {
+        return NSMacOSRomanStringEncoding;
+    }
+            
+    LangCode lang;
+    RegionCode region;
+    error = LocaleStringToLangAndRegionCodes([locale UTF8String], &lang, &region);
+    [locale release];
+    if (error != noErr) {
+        return NSMacOSRomanStringEncoding;
+    }
+    
+    TextEncoding encoding;
+    error = UpgradeScriptInfoToTextEncoding(kTextScriptDontCare, lang, region, NULL, &encoding);
+    if (error != noErr) {
+        return NSMacOSRomanStringEncoding;
+    }
+    
+    return CFStringConvertEncodingToNSStringEncoding(encoding);
 }
 
 @end
diff --git a/WebKit/Misc.subproj/WebNSObjectExtras.h b/WebKit/Misc.subproj/WebNSObjectExtras.h
new file mode 100644
index 0000000..d54ea58
--- /dev/null
+++ b/WebKit/Misc.subproj/WebNSObjectExtras.h
@@ -0,0 +1,23 @@
+/*
+    WebNSObjectExtras.h
+    Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ */
+
+#import <Foundation/Foundation.h>
+
+static inline id WebMakeCollectable(CFTypeRef obj)
+{
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
+    return (id)obj;
+#else
+    return (id)CFMakeCollectable(obj);
+#endif
+}
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
+
+ at interface NSObject (WebExtras)
+- (void)finalize;
+ at end
+
+#endif
diff --git a/WebKit/Misc.subproj/WebNSURLExtras.m b/WebKit/Misc.subproj/WebNSURLExtras.m
index 501586f..0a66d32 100644
--- a/WebKit/Misc.subproj/WebNSURLExtras.m
+++ b/WebKit/Misc.subproj/WebNSURLExtras.m
@@ -8,6 +8,7 @@
 
 #import <WebKit/WebAssertions.h>
 #import <WebKit/WebNSDataExtras.h>
+#import <WebKit/WebNSObjectExtras.h>
 
 #import <Foundation/NSString_NSURLExtras.h>
 #import <Foundation/NSURLProtocolPrivate.h>
@@ -332,9 +333,9 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
         // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
         // could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back
         // onto using ISO Latin 1 in those cases.
-        result = (NSURL *)CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES);
+        result = WebMakeCollectable(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
         if (!result) {
-            result = (NSURL *)CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES);
+            result = WebMakeCollectable(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
         }
         [result autorelease];
     }
@@ -560,7 +561,7 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
     }
     
     NSURL *result = changed
-        ? [(NSURL *)CFURLCreateAbsoluteURLWithBytes(NULL, buffer, bytesFilled, kCFStringEncodingUTF8, nil, YES) autorelease]
+        ? [WebMakeCollectable(CFURLCreateAbsoluteURLWithBytes(NULL, buffer, bytesFilled, kCFStringEncodingUTF8, nil, YES)) autorelease]
         : self;
 
     if (buffer != static_buffer) {
@@ -735,7 +736,8 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
         NSString *substring = [self substringWithRange:range];
         substring = (NSString *)CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef)substring, CFSTR(""));
         if (substring != nil) {
-            string = [substring autorelease];
+            string = [[substring retain] autorelease];
+            CFRelease(substring);
             range = NSMakeRange(0, [string length]);
         }
     }
diff --git a/WebKit/Plugins.subproj/WebBaseNetscapePluginStream.m b/WebKit/Plugins.subproj/WebBaseNetscapePluginStream.m
index 1ea035e..06a63c0 100644
--- a/WebKit/Plugins.subproj/WebBaseNetscapePluginStream.m
+++ b/WebKit/Plugins.subproj/WebBaseNetscapePluginStream.m
@@ -4,9 +4,11 @@
 */
 
 #import <WebKit/WebBaseNetscapePluginStream.h>
+
 #import <WebKit/WebBaseNetscapePluginView.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebNetscapePluginPackage.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 
 #import <Foundation/NSURLResponse.h>
@@ -30,14 +32,30 @@
     }
 
     [URL release];
-    free((void *)stream.url);
-    free(path);
     [plugin release];
     [deliveryData release];
     
+    free((void *)stream.url);
+    free(path);
+
     [super dealloc];
 }
 
+- (void)finalize
+{
+    ASSERT(stream.ndata == nil);
+
+    // FIXME: Bad for all the reasons mentioned above, but even worse for GC.
+    if (path) {
+        unlink(path);
+    }
+
+    free((void *)stream.url);
+    free(path);
+
+    [super finalize];
+}
+
 - (uint16)transferMode
 {
     return transferMode;
diff --git a/WebKit/Plugins.subproj/WebBaseNetscapePluginView.m b/WebKit/Plugins.subproj/WebBaseNetscapePluginView.m
index 2988f21..7fee8f4 100644
--- a/WebKit/Plugins.subproj/WebBaseNetscapePluginView.m
+++ b/WebKit/Plugins.subproj/WebBaseNetscapePluginView.m
@@ -16,6 +16,7 @@
 #import <WebKit/WebKitNSStringExtras.h>
 #import <WebKit/WebNetscapePluginStream.h>
 #import <WebKit/WebNullPluginView.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebNetscapePluginPackage.h>
@@ -1051,28 +1052,47 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
     return self;
 }
 
--(void)dealloc
+- (void)freeAttributeKeysAndValues
 {
     unsigned i;
+    for (i = 0; i < argsCount; i++) {
+        free(cAttributes[i]);
+        free(cValues[i]);
+    }
+    free(cAttributes);
+    free(cValues);
+}
 
+- (void)dealloc
+{
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     
     [self stop];
 
-    for (i = 0; i < argsCount; i++) {
-        free(cAttributes[i]);
-        free(cValues[i]);
-    }
     [plugin release];
     [streams release];
     [MIMEType release];
     [baseURL release];
     [streamNotifications release];
-    free(cAttributes);
-    free(cValues);
+
+    [self freeAttributeKeysAndValues];
+
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+    // FIXME: Bad to stop at finalize time. Need to restructure code
+    // so that we're already stopped before we get to this point.
+    [self stop];
+
+    [self freeAttributeKeysAndValues];
+
+    [super finalize];
+}
+
 - (void)drawRect:(NSRect)rect
 {
     if (!isStarted) {
@@ -1254,13 +1274,10 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
         return nil;
     }
     
-    NSString *string = (NSString *)CFStringCreateWithCString(kCFAllocatorDefault, URLCString, kCFStringEncodingWindowsLatin1);
-    NSString *URLString = [string _web_stringByStrippingReturnCharacters];
-    [string release];
-    
+    CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, URLCString, kCFStringEncodingWindowsLatin1);
+    NSString *URLString = [(NSString *)string _web_stringByStrippingReturnCharacters];
     NSURL *URL = [NSURL _web_URLWithDataAsString:URLString relativeToURL:baseURL];
-    
-
+    CFRelease(string);
     if (!URL) {
         return nil;
     }
@@ -1399,6 +1416,7 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
         WebFrame *frame = [self webFrame];
         if (JSString != nil && target != nil && [frame findFrameNamed:target] != frame) {
             // For security reasons, only allow JS requests to be made on the frame that contains the plug-in.
+            CFRelease(target);
             return NPERR_INVALID_PARAM;
         }
         
@@ -1406,7 +1424,9 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
         WebPluginRequest *pluginRequest = [[WebPluginRequest alloc] initWithRequest:request frameName:target notifyData:notifyData];
         [self performSelector:@selector(loadPluginRequest:) withObject:pluginRequest afterDelay:0];
         [pluginRequest release];
-        [target release];
+        if (target) {
+            CFRelease(target);
+        }
     } else {
         WebNetscapePluginStream *stream = [[WebNetscapePluginStream alloc]
             initWithRequest:request pluginPointer:instance notifyData:notifyData];
@@ -1465,7 +1485,7 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
             path = bufString;
         }
         postData = [NSData dataWithContentsOfFile:[path _web_fixedCarbonPOSIXPath]];
-        [bufString release];
+        CFRelease(bufString);
         if (!postData) {
             return NPERR_FILE_NOT_FOUND;
         }
@@ -1577,11 +1597,11 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
         return;
     }
 
-    NSString *status = (NSString *)CFStringCreateWithCString(NULL, message, kCFStringEncodingWindowsLatin1);
+    CFStringRef status = CFStringCreateWithCString(NULL, message, kCFStringEncodingWindowsLatin1);
     LOG(Plugins, "NPN_Status: %@", status);
     WebView *wv = [self webView];
-    [[wv _UIDelegateForwarder] webView:wv setStatusText:status];
-    [status release];
+    [[wv _UIDelegateForwarder] webView:wv setStatusText:(NSString *)status];
+    CFRelease(status);
 }
 
 -(void)invalidateRect:(NPRect *)invalidRect
diff --git a/WebKit/Plugins.subproj/WebBasePluginPackage.m b/WebKit/Plugins.subproj/WebBasePluginPackage.m
index 0f8097f..27e7b6f 100644
--- a/WebKit/Plugins.subproj/WebBasePluginPackage.m
+++ b/WebKit/Plugins.subproj/WebBasePluginPackage.m
@@ -9,9 +9,9 @@
 #import <WebKit/WebBasePluginPackage.h>
 
 #import <WebKit/WebNetscapePluginPackage.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebPluginPackage.h>
 
-
 @interface NSArray (WebPluginExtensions)
 - (NSArray *)_web_lowercaseStrings;
 @end;
@@ -49,9 +49,9 @@
     }
 
     if (wasAliased) {
-        NSURL *URL = (NSURL *)CFURLCreateFromFSRef(kCFAllocatorDefault, &fref);
-        newPath = [URL path];
-        [URL release];
+        CFURLRef URL = CFURLCreateFromFSRef(kCFAllocatorDefault, &fref);
+        newPath = [(NSURL *)URL path];
+        CFRelease(URL);
     }
 
     return newPath;
@@ -166,6 +166,14 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    // FIXME: Bad design to unload at dealloc/finalize time.
+    // Must be fixed for GC.
+    [self unload];
+    [super finalize];
+}
+
 - (NSString *)name
 {
     return name;
diff --git a/WebKit/WebCoreSupport.subproj/WebBridge.m b/WebKit/WebCoreSupport.subproj/WebBridge.m
index 164e04e..d1283ae 100644
--- a/WebKit/WebCoreSupport.subproj/WebBridge.m
+++ b/WebKit/WebCoreSupport.subproj/WebBridge.m
@@ -29,6 +29,7 @@
 #import <WebKit/WebKitSystemBits.h>
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
 #import <WebKit/WebNetscapePluginPackage.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebNullPluginView.h>
 #import <WebKit/WebPlugin.h>
@@ -113,7 +114,7 @@ NSString *WebPluginContainerKey =   @"WebPluginContainer";
     return self;
 }
 
-- (void)dealloc
+- (void)fini
 {
     ASSERT(_frame == nil);
 
@@ -123,12 +124,22 @@ NSString *WebPluginContainerKey =   @"WebPluginContainer";
         [[NSNotificationCenter defaultCenter] 
             removeObserver:self name:WebPreferencesChangedNotification object:nil];
     }
-    
+
     --WebBridgeCount;
-    
+}
+
+- (void)dealloc
+{
+    [self fini];
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [self fini];
+    [super finalize];
+}
+
 - (WebFrame *)webFrame
 {
     return _frame;
diff --git a/WebKit/WebCoreSupport.subproj/WebGlyphBuffer.m b/WebKit/WebCoreSupport.subproj/WebGlyphBuffer.m
index e086f7c..df9fe0e 100644
--- a/WebKit/WebCoreSupport.subproj/WebGlyphBuffer.m
+++ b/WebKit/WebCoreSupport.subproj/WebGlyphBuffer.m
@@ -3,10 +3,11 @@
     Copyright 2002, Apple, Inc. All rights reserved.
 */
 
-#import <CoreGraphics/CoreGraphicsPrivate.h>
-
 #import "WebGlyphBuffer.h"
 
+#import "WebNSObjectExtras.h"
+
+#import <CoreGraphics/CoreGraphicsPrivate.h>
 
 @implementation WebGlyphBuffer
 
@@ -42,7 +43,6 @@
     bufferedCount = 0;
 }
 
-
 - (void)dealloc
 {
     [font release];
@@ -51,6 +51,11 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [self reset];
+    [super finalize];
+}
 
 - (void)drawInView: (NSView *)targetView
 {
diff --git a/WebKit/WebCoreSupport.subproj/WebImageRenderer.m b/WebKit/WebCoreSupport.subproj/WebImageRenderer.m
index 00713c1..f7223a4 100644
--- a/WebKit/WebCoreSupport.subproj/WebImageRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebImageRenderer.m
@@ -3,12 +3,13 @@
 	Copyright (c) 2002, 2003, Apple, Inc. All rights reserved.
 */
 
-#import <WebKit/WebAssertions.h>
 #import <WebKit/WebImageRenderer.h>
+
+#import <WebKit/WebAssertions.h>
 #import <WebKit/WebImageRendererFactory.h>
+#import <WebKit/WebNSObjectExtras.h>
 
 #import <WebCore/WebCoreImageRenderer.h>
-#import <WebKit/WebAssertions.h>
 
 #import <CoreGraphics/CGContextGState.h>
 
@@ -66,57 +67,68 @@ extern NSString *NSImageLoopCount;
 	_bounds     = b;
 	_isFlipped  = YES;
         if (context)
-            _cgsContext = (CGContextRef)CFRetain(context);
+            _cgsContext = CGContextRetain(context);
     }
     
     return self;
 }
 
-- (void)dealloc {
-    
-    // done with focus stack
-    //
-    [_focusStack release]; _focusStack = nil;
-    
-    // done with context we own
-    //
-    CGContextRelease(_cgsContext); _cgsContext = NULL;
-    
+- (void)dealloc
+{
+    [_focusStack release];
+    if (_cgsContext) {
+        CGContextRelease(_cgsContext);
+    }
     [super dealloc];
 }
 
-- (void)saveGraphicsState {
+- (void)finalize
+{
+    if (_cgsContext) {
+        CGContextRelease(_cgsContext);
+    }
+    [super dealloc];
+}
+
+- (void)saveGraphicsState
+{
     if (_cgsContext) {
         CGContextSaveGState(_cgsContext);
     }
 }
 
-- (void)restoreGraphicsState {
+- (void)restoreGraphicsState
+{
     if (_cgsContext) {
         CGContextRestoreGState(_cgsContext);
     }
 }
 
-- (BOOL)isDrawingToScreen {
+- (BOOL)isDrawingToScreen
+{
     return NO;
 }
 
-- (void *)focusStack {
+- (void *)focusStack
+{
     if (!_focusStack) _focusStack = [[NSFocusStack allocWithZone:NULL] init];
     return _focusStack;
 }
 
-- (void)setFocusStack:(void *)stack {
+- (void)setFocusStack:(void *)stack
+{
     id oldstack = _focusStack;
     _focusStack = [(id)stack retain];
     [oldstack release];
 }
 
-- (NSRect)bounds {
+- (NSRect)bounds
+{
     return _bounds;
 }
 
-- (BOOL)isFlipped {
+- (BOOL)isFlipped
+{
     return _isFlipped;
 }
 
@@ -369,15 +381,26 @@ static NSMutableSet *activeImageRenderers;
     [originalData release];
     
     if (context) {
-        CFRelease (context);
-        context = 0;
+        CFRelease(context);
     }
-    
+
     [_PDFDoc release];
-    
+
     [super dealloc];
 }
 
+- (void)finalize
+{
+    ASSERT(frameTimer == nil);
+    ASSERT(frameView == nil);
+
+    if (context) {
+        CFRelease(context);
+    }
+
+    [super finalize];
+}
+
 - (id)firstRepProperty:(NSString *)propertyName
 {
     id firstRep = [[self representations] objectAtIndex:0];
@@ -651,11 +674,11 @@ static NSMutableSet *activeImageRenderers;
 {
     compositeOperator = operator;
     
-    if (context != aContext) {
-        if (context)
-            CFRelease (context);
+    if (aContext != context) {
         if (aContext)
-            CFRetain (aContext);
+            CFRetain(aContext);
+        if (context)
+            CFRelease(context);
         context = aContext;
     }
         
@@ -808,6 +831,12 @@ static void ReleasePDFDocumentData(void *info, const void *data, size_t size) {
     [super dealloc];
 }
 
+- (void)finalize
+{
+    if (_document != NULL) CGPDFDocumentRelease(_document);
+    [super finalize];
+}
+
 - (CGPDFDocumentRef) documentRef
 {
     return _document;
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index 58145f5..b3b9202 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -355,6 +355,7 @@
 				51863EDA065417DA00E9E8DD,
 				51863EFD065419EB00E9E8DD,
 				93185DB606679F42005D5E7E,
+				93D1FE14067EB10B009CE68A,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -552,6 +553,7 @@
 				BE887C00056D3A6E009BB3E7,
 				8398847A03426FB000BC5F5E,
 				8398847B03426FB000BC5F5E,
+				93D1FE13067EB10B009CE68A,
 				ED2B2474033A2DA800C1A526,
 				ED2B2475033A2DA800C1A526,
 				EDD1A5C605C83987008E3150,
@@ -2996,6 +2998,20 @@
 			settings = {
 			};
 		};
+		93D1FE13067EB10B009CE68A = {
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			lastKnownFileType = sourcecode.c.h;
+			path = WebNSObjectExtras.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		93D1FE14067EB10B009CE68A = {
+			fileRef = 93D1FE13067EB10B009CE68A;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		93D623DD051E791F002F47DD = {
 			isa = PBXFileReference;
 			lastKnownFileType = "compiled.mach-o.dylib";
diff --git a/WebKit/WebView.subproj/WebDataProtocol.m b/WebKit/WebView.subproj/WebDataProtocol.m
index e22612d..d1e6e5c 100644
--- a/WebKit/WebView.subproj/WebDataProtocol.m
+++ b/WebKit/WebView.subproj/WebDataProtocol.m
@@ -65,7 +65,7 @@ static NSString *WebDataRequestPropertyKey = @"WebDataRequest";
     NSString *UUIDString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, UUIDRef);
     CFRelease(UUIDRef);
     NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", WebDataProtocolScheme, UUIDString]];
-    [UUIDString release];
+    CFRelease(UUIDString);
     return URL;
 }
 
diff --git a/WebKit/WebView.subproj/WebDataSource.m b/WebKit/WebView.subproj/WebDataSource.m
index 91ce89e..4ff37e6 100644
--- a/WebKit/WebView.subproj/WebDataSource.m
+++ b/WebKit/WebView.subproj/WebDataSource.m
@@ -30,6 +30,7 @@
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebKitStatisticsPrivate.h>
 #import <WebKit/WebMainResourceClient.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebResourceLoadDelegate.h>
 #import <WebKit/WebResourcePrivate.h>
@@ -61,7 +62,6 @@
     [pageTitle release];
     [response release];
     [mainDocumentError release];
-    [iconLoader setDelegate:nil];
     [iconLoader release];
     [iconURL release];
     [ourBackForwardItems release];
@@ -1049,11 +1049,21 @@
 {
     --WebDataSourceCount;
     
+    [_private->iconLoader setDelegate:nil];
     [_private release];
     
     [super dealloc];
 }
 
+- (void)finalize
+{
+    --WebDataSourceCount;
+
+    [_private->iconLoader setDelegate:nil];
+
+    [super finalize];
+}
+
 - (NSData *)data
 {
     return _private->resourceData;
@@ -1128,7 +1138,12 @@
             break;
         }
     }
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
     [pool release];
+#else
+    [pool drain];
+#endif
     
     return childFrame != nil;
 }
diff --git a/WebKit/WebView.subproj/WebFrame.m b/WebKit/WebView.subproj/WebFrame.m
index c10ba2f..ee31ff8 100644
--- a/WebKit/WebView.subproj/WebFrame.m
+++ b/WebKit/WebView.subproj/WebFrame.m
@@ -24,6 +24,7 @@
 #import <WebKit/WebKitStatisticsPrivate.h>
 #import <WebKit/WebNetscapePluginDocumentView.h>
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebNullPluginView.h>
 #import <WebKit/WebPreferencesPrivate.h>
@@ -176,10 +177,6 @@ NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
 
 - (void)dealloc
 {
-    [webFrameView _setWebView:nil];
-    [dataSource _setWebView:nil];
-    [provisionalDataSource _setWebView:nil];
-
     [name release];
     [webFrameView release];
     [dataSource release];
@@ -2481,13 +2478,31 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
 
 - (void)dealloc
 {
-    --WebFrameCount;
-
     [self _detachFromParent];
+    [_private->webFrameView _setWebView:nil];
+    [_private->dataSource _setWebView:nil];
+    [_private->provisionalDataSource _setWebView:nil];
+
     [_private release];
+
+    --WebFrameCount;
+
     [super dealloc];
 }
 
+- (void)finalize
+{
+    // FIXME: Should not do this work at finalize time. Need to do it at a predictable time instead.
+    [self _detachFromParent];
+    [_private->webFrameView _setWebView:nil];
+    [_private->dataSource _setWebView:nil];
+    [_private->provisionalDataSource _setWebView:nil];
+
+    --WebFrameCount;
+
+    [super finalize];
+}
+
 - (NSString *)name
 {
     return [_private name];
diff --git a/WebKit/WebView.subproj/WebFrameView.m b/WebKit/WebView.subproj/WebFrameView.m
index e656b10..6d0a45b 100644
--- a/WebKit/WebView.subproj/WebFrameView.m
+++ b/WebKit/WebView.subproj/WebFrameView.m
@@ -20,6 +20,7 @@
 #import <WebKit/WebKeyGenerator.h>
 #import <WebKit/WebKitErrorsPrivate.h>
 #import <WebKit/WebKitStatisticsPrivate.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebTextRendererFactory.h>
@@ -454,6 +455,15 @@ static NSMutableDictionary *viewTypes;
     [super dealloc];
 }
 
+- (void)finalize 
+{
+    --WebFrameViewCount;
+
+    _private = nil;
+
+    [super finalize];
+}
+
 - (WebFrame *)webFrame
 {
     return [[self _webView] _frameForView: self]; 
diff --git a/WebKit/WebView.subproj/WebHTMLRepresentation.m b/WebKit/WebView.subproj/WebHTMLRepresentation.m
index f68b7e4..a132d30 100644
--- a/WebKit/WebView.subproj/WebHTMLRepresentation.m
+++ b/WebKit/WebView.subproj/WebHTMLRepresentation.m
@@ -13,6 +13,7 @@
 #import <WebKit/WebDocumentPrivate.h>
 #import <WebKit/WebFramePrivate.h>
 #import <WebKit/WebKitStatisticsPrivate.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebResourcePrivate.h>
 
 #import <Foundation/NSString_NSURLExtras.h>
@@ -59,6 +60,13 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    --WebHTMLRepresentationCount;
+
+    [super finalize];
+}
+
 - (WebBridge *)_bridge
 {
     return _private->bridge;
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 6cd0efb..70b2d58 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -27,6 +27,7 @@
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
 #import <WebKit/WebNSEventExtras.h>
 #import <WebKit/WebNSImageExtras.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSPrintOperationExtras.h>
 #import <WebKit/WebNSURLExtras.h>
@@ -139,8 +140,6 @@ static WebElementOrTextFilter *elementOrTextFilterInstance = nil;
     ASSERT(autoscrollTimer == nil);
     ASSERT(autoscrollTriggerEvent == nil);
     
-    [pluginController destroyAllPlugins];
-    
     [mouseDownEvent release];
     [draggingImageURL release];
     [pluginController release];
@@ -1120,11 +1119,22 @@ static WebHTMLView *lastHitView = nil;
     [self _clearLastHitViewIfSelf];
     [self _reset];
     [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [_private->pluginController destroyAllPlugins];
     [_private release];
     _private = nil;
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [self _clearLastHitViewIfSelf];
+    [self _reset];
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [_private->pluginController destroyAllPlugins];
+    _private = nil;
+    [super finalize];
+}
+
 - (IBAction)takeFindStringFromSelection:(id)sender
 {
     if (![self _haveSelection]) {
diff --git a/WebKit/WebView.subproj/WebImageView.m b/WebKit/WebView.subproj/WebImageView.m
index 56f9fcd..9cd4066 100644
--- a/WebKit/WebView.subproj/WebImageView.m
+++ b/WebKit/WebView.subproj/WebImageView.m
@@ -12,6 +12,7 @@
 #import <WebKit/WebImageRenderer.h>
 #import <WebKit/WebImageRendererFactory.h>
 #import <WebKit/WebImageRepresentation.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebViewPrivate.h>
@@ -49,6 +50,12 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [[rep image] stopAnimation];
+    [super finalize];
+}
+
 - (BOOL)haveCompleteImage
 {
     NSSize imageSize = [[rep image] size];
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.m b/WebKit/WebView.subproj/WebMainResourceClient.m
index b6abf6a..069e420 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.m
+++ b/WebKit/WebView.subproj/WebMainResourceClient.m
@@ -27,6 +27,7 @@
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitErrorsPrivate.h>
 #import <WebKit/WebKitLogging.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebPolicyDelegatePrivate.h>
 #import <WebKit/WebViewPrivate.h>
@@ -58,6 +59,12 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [proxy setDelegate:nil];
+    [super finalize];
+}
+
 - (void)receivedError:(NSError *)error
 {
     // Calling _receivedError will likely result in a call to release, so we must retain.
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.m b/WebKit/WebView.subproj/WebMainResourceLoader.m
index b6abf6a..069e420 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.m
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.m
@@ -27,6 +27,7 @@
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitErrorsPrivate.h>
 #import <WebKit/WebKitLogging.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebPolicyDelegatePrivate.h>
 #import <WebKit/WebViewPrivate.h>
@@ -58,6 +59,12 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [proxy setDelegate:nil];
+    [super finalize];
+}
+
 - (void)receivedError:(NSError *)error
 {
     // Calling _receivedError will likely result in a call to release, so we must retain.
diff --git a/WebKit/WebView.subproj/WebTextView.m b/WebKit/WebView.subproj/WebTextView.m
index 857cb73..40c21cf 100644
--- a/WebKit/WebView.subproj/WebTextView.m
+++ b/WebKit/WebView.subproj/WebTextView.m
@@ -12,6 +12,7 @@
 #import <WebKit/WebDocument.h>
 #import <WebKit/WebDocumentInternal.h>
 #import <WebKit/WebFrameViewPrivate.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebPreferences.h>
 #import <WebKit/WebTextRendererFactory.h>
@@ -60,6 +61,12 @@
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [super finalize];
+}
+
 - (float)_textSizeMultiplierFromWebView
 {
     // Note that we are not guaranteed to be the subview of a webView at any given time.
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index fdfdc7d..ac06ff0 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -37,8 +37,9 @@
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebKitStatisticsPrivate.h>
+#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSPasteboardExtras.h>
-#import "WebNSPrintOperationExtras.h"
+#import <WebKit/WebNSPrintOperationExtras.h>
 #import <WebKit/WebNSEventExtras.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebNSViewExtras.h>
@@ -1384,6 +1385,19 @@ NS_ENDHANDLER
     [super dealloc];
 }
 
+- (void)finalize
+{
+    [self _close];
+
+    --WebViewCount;
+
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+    [WebPreferences _removeReferenceForIdentifier: [self preferencesIdentifier]];
+
+    [super finalize];
+}
+
 - (void)setPreferences: (WebPreferences *)prefs
 {
     if (_private->preferences != prefs){

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list