[Openmcl-devel] Retain/Release and the ObjC Bridge
bfulg at pacbell.net
Wed Aug 29 03:59:33 UTC 2007
The new Cocoa bridge is great to work with, but I'm a little confused
as to the semantics of releasing data from the bridge. Should we
treat the Lisp objects returned by API calls just as we would in C
(i.e., we must manually call release in many cases), or does OpenMCL
ever clean up when objects go out of scope?
(let* ((Name (%make-nsstring (native-translated-namestring
(url (#_CFURLCreateWithFileSystemPath (%null-ptr)
Name #$kCFURLPOSIXPathStyle #$NO))
(imageSrcRef (#_CGImageSourceCreateWithURL url (%null-ptr)))
(imageRef (#_CGImageSourceCreateImageAtIndex imageSrcRef
(uprightImage (#/imageWithCGImage: (@class c-i-image)
(if (%null-ptr-p uprightImage)
(error "cannot decode texture file \"~A\"" (native-translated-
(let* ( ;; Flip image (if necessary)
(image (if Flip-Vertical (#/imageByApplyingTransform:
uprightImage transform) uprightImage))
(rect (#/extent image))
(depth (#_CGImageGetBitsPerPixel imageRef))
(width (#_CGImageGetWidth imageRef))
(height (#_CGImageGetHeight imageRef))
(bytesPerRow (#_CGImageGetBytesPerRow imageRef))
(bytesPerPixel (truncate depth 8))
(bitmap (#/initWithCIImage: (#/alloc (@class n-s-bitmap-
(Codec (#/bitmapFormat bitmap))
(samples-per-pixel (#/samplesPerPixel bitmap)))
(format t "~%-loading image ~A size: ~A x ~A, depth: ~A"
Filename width height depth)
(format t "---> bytes-per-pixel/samples-per-pixel: ~A/~A~%"
bytesPerPixel bytesPerPixel) ;samples-per-pixel)
(format t "---> bitmap format: ~A~%" (#/bitmapFormat
;; FIXME: Need Core Image filters to change depth if required
(when Forced-Depth (setq depth Forced-Depth)) ; Currently we
don't do anything with this ...
This code seems to work fine for me, but I'm wondering if the
CFRelease calls I am making are always necessary. Or am I perhaps
missing some (perhaps the URL should be released, too?)
And to add further confusion, will the answer to the above change when
Objective C 2.0 is used? -- I would imagine it must if garbage
collection is used.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Openmcl-devel