IDE: VS 2015
Version: 8.4.96.2041
Target (If relevant): iOS
Description:
iOSTest.zip (106.3 KB)
public class AtomRef<T> where T : class {
private volatile object mValue;
public AtomRef (T value) {
mValue = value;
}
public T get() => (T)mValue;
public void set(T value) => mValue = value;
}
public class TagObject {
public readonly int tag;
public TagObject(int t) {
tag = t;
}
public override void dealloc() {
NSLog("%@", $"obj{tag} dealloc!!");
}
}
[UIApplicationMain, IBObject]
class AppDelegate : IUIApplicationDelegate {
public UIWindow window { get; set; }
public BOOL application(UIApplication application) didFinishLaunchingWithOptions(NSDictionary launchOptions) {
window = new UIWindow(UIScreen.mainScreen().bounds);
window.rootViewController = new UIViewController withNibName(null) bundle(null);
window.makeKeyAndVisible();
var obj1 = new TagObject(1);
var obj2 = new TagObject(2);
var a = new AtomRef<TagObject>(obj1);
a.set(obj2);
/*
This line will cause the leak of obj1:
1) if comment it, "object1 dealloc" will be printed;
2) if uncomment it, "object1 dealloc" will never be printed;
*/
obj1 = null;
return true;
}
Really weird issue. If uncomment:
If comment: