Memory management with macruby and Objective-C
I have an application macruby
that leaks gigs of memory. Ruby for booleans and accessing some of my Objective-C classes, for accessing functions like the Accessibility-API, and for taking some screenshots and handling them through CIImage.
Has ruby and Objective-C code that handles memory?
Ruby collects garbage automatically as far as I know, but for Obj.-C I need to use some NSAutoreleasePool
. But where should I release
pool? My ruby code has to handle return values.
In my project settings I have garbage collection ( -fobjc-gc-only
) enabled .
Here's some code:
+ (CGSize) getSizeAttribute: (AXUIElementRef) element attribute: (CFStringRef) attribute {
AXValueRef temp;
CGSize point;
AXError resultCode;
resultCode = AXUIElementCopyAttributeValue (element, attribute, (CFTypeRef *) & temp);
AXValueGetValue (temp, kAXValueCGSizeType, & point);
return point;
}
In your code
resultCode = AXUIElementCopyAttributeValue( element, attribute, (CFTypeRef *)&temp );
temp is never released.
You must add:
CFMakeCollectable(temp)
MacRuby apps run in GC mode by default, but CF / Obj-C memory management can be a little tricky (outside of MacRuby), check the Apple documentation on their website.
a source to share