内存管理.

#import "ViewController.h"

#import "Fish.h"

#import "Cat.h"

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    Cat * cat =[[Cat alloc]init];

    Fish * seafish =[[Fish alloc]init];

    Fish * goldfish =[[Fish alloc]init];

    [cat EatGoldfish:goldfish];

   [cat EatSeafish:seafish];

    [cat setGoldfish : seafish];

    [cat gotocathgoldfish];

    [cat release];

    [seafish release];

    [goldfish release];

    

}

 

#import "Fish.h"

 

@implementation Fish

 

- (void)goldFishMeet_cat;

{

    NSLog(@"the fish meet cat ,it still here.....");

}

- (void)seaFishMeet_cat;

{

    NSLog(@"the fish m

eet cat,it run at once");

}

#import "Cat.h"

 

@implementation Cat

 

- (void)EatSeafish:(Fish *)seafish;

{

    NSLog(@"the cat do not eat seafish");

    

    

        

}

- (void) setGoldfish :(Fish *) fish

{

   _goldfish = fish;

}

- (void)EatGoldfish:(Fish *)goldfish;

{

    NSLog(@"the cat like goldfish,but cat do not like goldfish");

    

}

- (void)gotocathgoldfish

{

    

    [_goldfish  goldFishMeet_cat];

}

- (void)gotocathseafish

{

    [_seafish  seaFishMeet_cat];

}

 

 

- (void)dealloc;

{

    [_seafish release];

    [_goldfish release];

    [super dealloc];

}

@end

 

 

@end

 

posted @ 2014-10-08 19:25  汪伟  阅读(130)  评论(0编辑  收藏  举报