[SR-1330] Memory Leaked when access a OC-Bridged Instance property from Swift Class #43938
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
memory leak
bug: Memory leak
Environment
Swift2.2 Xcode 7.3
Additional Detail from JIRA
md5: cc8e7706fd0f2c6112bb7ced3b19949e
Issue Description:
I'm migrating a module using swift which wrote by Objc before.
But sadly there was some history problem that I can not write pure-swift language for the module,for the reason that some other modules was too complicated to rewrite.So I try to mixed objc and swift in the new module.
Conditions to leak:
1.A swift class that has a instance variable which type is AnyObject, or a Objc class with type id.
2.a function or method that try to access any property on the instance of AnyObject or id.
result:
3.A objc class that declare a field with the name step(2) accessed.
the property accessed in step2 will be retain+1,and never be released after. So the object leaked.
subdata is a property on a Objc-bridged class,like:
So the compiler will not show any error.In other word,you can write any property accessing code which was belong to any objc-bridged class.
Such as,the length property on NSString. So you can write without compiler error:
I think this situation is similar to the [NSObject performSelector] call,
When you try to perform a selector on some object,compiler will give you a potential memory leak warning.ARC-auto-inserted can not work well in the compile phase,because of the selector maybe return a object or not.So the compiler will not release the returned value on [performSelector] call.
Suggestion:
or
2.auto insert arc code in compile phase.
The text was updated successfully, but these errors were encountered: