• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I think I am leaking! :)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think I am leaking! :)


  • Subject: Re: I think I am leaking! :)
  • From: John Hörnkvist <email@hidden>
  • Date: Mon, 29 Oct 2001 02:59:44 +0100

Replying to myself here...

On Sunday, October 28, 2001, at 02:31 AM, John Hvrnkvist wrote:


On Sunday, October 28, 2001, at 02:43 AM, Andrew Platzer wrote:

For the NSHTTPURLHandle, that's more difficult. If this is for an application that you want to ship, please contact me and we can figure something out. I have to talk to the owner of the code about these problems.

This is rather easy actually; all you need to do is to give the old dealloc method another name and install your own dealloc method in its place, or just keep a pointer to the old dealloc implementation.
<Snip>

Since the last snippet wasn't clear enough, here's a repeat:

#import <objc/objc-class.h>
#import <Foundation/Foundation.h>

extern void _objc_flush_caches(Class);

@interface NSHTTPURLHandle:NSURLHandle
@end

@implementation NSHTTPURLHandle(DeallocPatch)

static IMP NSHTTPURLHandle_dealloc=nil;

+ (void)install_patch
{
struct objc_method *method;

NSHTTPURLHandle_dealloc=[self instanceMethodForSelector:@selector(dealloc)];

if (method = class_getInstanceMethod([self class], @selector(dealloc)))
{
method->method_imp = [self instanceMethodForSelector:@selector(my_dealloc)];
_objc_flush_caches([self class]);
}
}

- (void)my_dealloc
{
NSLog(@"Patched dealloc called");
NSHTTPURLHandle_dealloc(self,@selector(dealloc));
[super dealloc];
}
@end

Test case:

main()
{
NSAutoreleasePool* pool=[[NSAutoreleasePool alloc] init];
NSURLHandle* urlHandle;
[NSHTTPURLHandle install_patch];

urlHandle=[[NSHTTPURLHandle alloc] init];
[urlHandle release];

[pool release];
}

Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com


  • Prev by Date: Re: Currency Converter (tyler, you there ?)
  • Next by Date: Re: Auto-Completion
  • Previous by thread: Re: I think I am leaking! :)
  • Next by thread: Calling a CLI command withing the app
  • Index(es):
    • Date
    • Thread