Releasing WebView After Caching
Releasing WebView After Caching
- Subject: Releasing WebView After Caching
- From: Duncan Alexander Oliver <email@hidden>
- Date: Sun, 8 Jul 2007 10:59:22 -0500
I have an object set up to make a thumbnail of a web page using these
methods:
- (void)loadThumbnail
{
WebView *previewView = [[WebView alloc] initWithFrame:NSMakeRect
(0,0,1024,768)
frameName:@""
groupName:nil];
[previewView setFrameLoadDelegate:self];
[[[previewView mainFrame] frameView] setAllowsScrolling:NO];
[[previewView mainFrame] loadArchive:[[[WebArchive alloc]
initWithData:[NSData dataWithContentsOfFile:[self archivePath]]]
autorelease]];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)
frame
{
[NSTimer scheduledTimerWithTimeInterval:.5
target:self
selector:@selector(finishThumbnail:)
userInfo:sender
repeats:NO];
}
The half-second offset is due to a problem with one website that went
to this method before then WebView had loaded the contents of the
page. finishThumbnail looks like this:
- (void)finishThumbnail:(NSTimer *)timer
{
NSRect thumbnailRect = [[timer userInfo] visibleRect];
NSBitmapImageRep *viewBitmapImageRep = [[timer userInfo]
bitmapImageRepForCachingDisplayInRect:thumbnailRect];
[[[timer userInfo] autorelease] cacheDisplayInRect:thumbnailRect
toBitmapImageRep:viewBitmapImageRep];
[self setValue:[NSNumber numberWithBool:YES]
forKey:@"thumbnailIsLoaded"];
[self setValue:[viewBitmapImageRep TIFFRepresentation]
forKey:@"thumbnail"];
}
This setup seems to work with most sites I try except for these three:
www.penny-arcade.com
www.pvponline.com
www.digitalpimponline.com
After I grab the thumbnail from one of these three, the application
crashes when I move the mouse, kicking me to NSAutoreleasePool in the
debugger. Removing the timer from the equation and just grabbing the
thumbnail in the webView:didFinishLoadForFrame: causes me to get
kicked out in NSAutoreleasePool inside [NSURLConnection
(NSURLConnectionInternal) _sendCallbacks].
Removing the autorelease from finishThumbnail: fixes the crash, but I
can't think of anywhere else to release the WebView. I also can't
find the unifying characteristic that makes these three websites a
problem. It might be that they all have ads, but even then the format
for these ads are varying. Any ideas would be greatly appreciated.
---
Duncan Oliver
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden