zoukankan      html  css  js  c++  java
  • strong和weak的区别

    简单的说:strong是强引用,weak是弱引用。

    关于二者实际应用中的详细区别,可查看:http://blog.csdn.net/q199109106q/article/details/8565017

    代码示例:

           NSString *string = @"zhongguo";

        

        textField1 = [[UITextField alloc] init];

        textField1.frame = CGRectMake(10, 100, 100, 50);

        [self.view addSubview:textField1];

        

        textField2 = [[UITextField alloc] init];

        textField2.frame = CGRectMake(10, 200, 100, 50);

        [self.view addSubview:textField2];

        

        //strong

        textField1.text = string;

        NSString *name1 = textField1.text;

        

        NSLog(@"textField1 ---> %@",textField1.text);//textField1 ---> zhongguo

        NSLog(@"name1 ---> %@",name1);//name1 ---> zhongguo

        

        textField1.text = @"textField1 ---> 01";

        

        NSLog(@"textField1 ---> %@",textField1.text);//textField1 ---> textField1 ---> 01

        NSLog(@"name1 ---> %@",name1);//name1 ---> zhongguo

        

        name1 = @"name1 ---> 01";

        

        NSLog(@"textField1 ---> %@",textField1.text);//textField1 ---> textField1 ---> 01

        NSLog(@"name1 ---> %@",name1);//name1 ---> name1 ---> 01


        

        NSLog(@" ");

        

        //weak

        textField2.text = string;

        __weak NSString *name2 = textField2.text;

        

        NSLog(@"textField2 ---> %@",textField2.text);//textField2 ---> zhongguo

        NSLog(@"name2 ---> %@",name2);//name2 ---> (null)

        

        textField2.text = @"textField2 ---> 01";


        NSLog(@"textField2 ---> %@",textField2.text);//textField2 ---> textField2 ---> 01

        NSLog(@"name2 ---> %@",name2);//name2 ---> (null)

  • 相关阅读:
    http://blog.csdn.net/sinat_33950284/article/details/50646622
    http://edu.csdn.net/course/detail/2798?ref=blog&loc=0
    微服务架构的分布式事务解决方案
    http://www.cnblogs.com/chenpi/p/5999707.html
    http://blog.csdn.net/hejingyuan6/article/details/47403299
    https://www.oschina.net/p/goshop2
    https://github.com/SuperMan42/MVP
    spring mvc
    http://www.iyaxi.com/2015-11-17/732.html
    场景测试
  • 原文地址:https://www.cnblogs.com/NINIiOS/p/4897231.html
Copyright © 2011-2022 走看看