Does Leaks report this as a leak or just as memory that's in use? There's no memory leak, per se, in this code. It's what happens to the UIImage object after it's returned that determines whether a leak happens or not. Do you add the UIImage to an array or a dictionary or a UIImageView or anything like that? The db doesn't have anything directly to do with this. Can you tell if it's the CGImageRef itself or the buffer that it creates that's living on?
There's a possibility that the images are being cached by the framework intentionally.
You could try changing that line to
Code:
UIImage* result = [[[UIImage alloc] initWithCGImage:ref] autorelease];
and see if that makes any difference.