Git Product home page Git Product logo

swift_learning's Introduction

swift_learning

iOS开发学习

AutoRelease的应用

//
//  main.m
//  objective_c
//
//  Created by 昊轩 on 2022/10/30.
//

#import <Foundation/Foundation.h>
#import "Human.h"
#import "Student.h"


/**
 1、系统自带的方法没有alloc、new、copy,说明返回的对象都是autorelease的对象
 2、开发中经常会提供一些类方法,创建一个已经release过的对象
 3、创建对象一般不用类名,一般用self
 */

int main() {
    Human *human001 = [[Human alloc] init];
    human001.age = 20;
    [human001 release];
    
    @autoreleasepool {
        Human *human002 = [Human human];
        human002.age = 101;
        NSLog(@"autorelease的应用");
        
//        humanWidthAge
        Human *human003 = [Human humanWidthAge: 22];
        NSLog(@"human003:%d", [human003 age]);
    }
//    Student
    @autoreleasepool {
        Student *student = [Student humanWidthAge: 28];
        student.money = 80;
        NSLog(@"Student money:%d", student.money);
    }
    return 0;
}


//2022-10-30 23:24:13.782763+0800 objective_c[8873:228217] Human 20 岁被销毁了
//2022-10-30 23:24:13.782977+0800 objective_c[8873:228217] autorelease的应用
//2022-10-30 23:24:13.782999+0800 objective_c[8873:228217] human003:22
//2022-10-30 23:24:13.783018+0800 objective_c[8873:228217] Human 22 岁被销毁了
//2022-10-30 23:24:13.783034+0800 objective_c[8873:228217] Human 101 岁被销毁了
//2022-10-30 23:24:13.783051+0800 objective_c[8873:228217] Student money:80
//2022-10-30 23:24:13.783067+0800 objective_c[8873:228217] Human 28 岁被销毁了

swift_learning's People

Contributors

tecode avatar

Stargazers

lybgo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.