object c ÄÚ´æ¹ÜÀí
¿´ÁËϹٷ½ÎĵµµÄ¹ØÓÚobject c µÄÄÚ´æ¹ÜÀí,×ܽáÏÂ:
ÔÚiphoneÖÐobject c ÖеÄÄÚ´æ¹ÜÀíÊÇͨ¹ý¼ÆÊýÆ÷À´¹ÜÀíµÄ,ÿ¸ö¶ÔÏóÄÚ²¿¶¼ÓÐÒ»¸ö¼ÆÊýÆ÷.н¨Ò»¸ö¶ÔÏó,»òÕßÕâ¸ö¶ÔÏ󱻯äËû¶ÔÏóÒýÓÃ,¶à»áʹ¼ÆÊýÆ÷¼Ó1.Retain Ôö¼Ó¼ÆÊýÆ÷Öµ release ¼õÉÙ¼ÆÊýÆ÷Öµ.µ±¼ÆÊýÆ÷Ϊ0ʱ¶ÔÏó¾Ídealloc×Ô¼º.
ÔÚobject cÖÐÄãÉú³ÉµÄÒ»¸ö¶ÔÏóÄÇôÄã¾ÍÓÐÔðÈÎÈ¥ÊÍ·ÅËü£¬ÄÚ´æ¹ÜÀíµÄÒ»°ã¹æÔò£º
You own any object you create by allocating memory for it or copying it.
Related methods: alloc, allocWithZone:, copy, copyWithZone:, mutableCopy, mutableCopyWithZone:
If you are not the creator of an object, but want to ensure it stays in memory for you to use, you can express an ownership interest in it.
Related method: retain
If you own an object, either by creating it or expressing an ownership interest, you are responsible for releasing it when you no longer need it.
Related methods: release, autorelease
Conversely, if you are not the creator of an object and have not expressed an ownership interest, you must not release it.
¿¼ÂÇÏÂÃæÕâ¸öÀý×Ó£º
Thingamajig *thingamajig = [[Thingamajig alloc] init];
NSArray *sprockets = [thingamajig sprockets];
[thingamajig release];
thingamajig ÐèÒªrelease£¬ÒòΪºÜÏÔÈ»ÕâÀïÎÒÃÇÊÇthingamajig µÄowner¡££¨µÚÒ»Ìõ¹æÔò£©
ÄÇôsprockets Ϊʲô²»ÐèÒªreleaseÄØ¡£
Ê×ÏÈÎÒÃDz»ÊÇ sprockets µÄ creater.£¨µÚÒ»Ìõ¹æÔò£©,ÎÒÃÇҲûÓÐexpressing an ownership interest£¬ÒòΪÎÒÃÇûÓÐ
retainËü£¬£¨µÚ¶þÌõ¹æÔò£© ËùÒÔÎÒÃDz»¸ºÔðreleaseËü¡£
¾ßÌåÀ´¿´ thingamajig µÄ sprockets·½·¨µÄʵÏÖ£º
(NSArray *)sprockets {
NSArray *array;
array = [[NSArray alloc] initWithObjects:mainSprocket,auxiliarySprocket, nil];
return [array autorelease];
}
¿É¼û·ÖÅäµÄÄÚ´æÔÚ·
Ïà¹ØÎĵµ£º
C/C++ÖÐStaticµÄ×÷ÓÃÏêÊö
1.ÏÈÀ´½éÉÜËüµÄµÚÒ»ÌõÒ²ÊÇ×îÖØÒªµÄÒ»Ìõ£ºÒþ²Ø¡£
µ±ÎÒÃÇͬʱ±àÒë¶à¸öÎļþʱ£¬ËùÓÐδ¼Óstaticǰ׺µÄÈ«¾Ö±äÁ¿ºÍº¯Êý¶¼¾ßÓÐÈ«¾Ö¿É¼ûÐÔ¡£ÎªÀí½âÕâ¾ä»°£¬ÎÒ¾ÙÀýÀ´ËµÃ÷¡£ÎÒÃÇҪͬʱ±àÒëÁ½¸öÔ´Îļþ£¬Ò»¸öÊÇa.c£¬ÁíÒ»¸öÊÇmain.c.
ÏÂÃæÊÇa.cµÄÄÚÈÝ£º
char a = 'A'; // global variable
void ......
Ò»¡¢ º¯Êý²ÎÊý´«µÝ»úÖÆµÄ»ù±¾ÀíÂÛ ¡¡¡¡º¯Êý²ÎÊý´«µÝ»úÖÆÎÊÌâÔÚ±¾ÖÊÉÏÊǵ÷Óú¯Êý£¨¹ý³Ì£©ºÍ±»µ÷Óú¯Êý£¨¹ý³Ì£©ÔÚµ÷Ó÷¢Éúʱ½øÐÐͨÐŵķ½·¨ÎÊÌâ¡£»ù±¾µÄ²ÎÊý´«µÝ»úÖÆÓÐÁ½ÖÖ£ºÖµ´«µÝºÍÒýÓô«µÝ¡£ÒÔÏÂÌÖÂ۳Ƶ÷ÓÃÆäËûº¯ÊýµÄº¯ÊýΪÖ÷µ÷º¯Êý£¬±»µ÷Óõĺ¯ÊýΪ±»µ÷º¯Êý¡£¡¡¡¡Öµ´«µÝ£¨passl-by-value£©¹ý³ÌÖУ¬±»µ÷º¯ÊýµÄÐÎʽ²Î ......
#include <stdio.h>
#include <stdlib.h>
#define SIZE 17
void reverse(int start, int end);
int data[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
int main(void)
{
int i = 5;
reverse(0, i - 1);
reverse(i, SIZE-1);
reverse(0, SIZE-1);
return ......
1¡¢CºÍC++¹»±¿£¬±ÆµÄ³ÌÐòÔ±×Ô¼º×öºÜ¶àÊ¡£
CÆäʵ´ó¼Ò¶¼ÖªµÀ£¬ÊÇÒ»ÃÅÖеͼ¶ÓïÑÔ£¬±£ÁôÁËÖ¸ÕëµÈ»ã±àÌØÕ÷£¬Óëϵͳµ×²ã½áºÏÃÜÇС£C++ÄØ£¬¸ü¶àµÄÏò¸öObject C£¬¼´ÃæÏò¶ÔÏóµÄC¡£µ«ÕâЩ£¬Æäʵ²¢²»Äܹ»ÈóÌÐòÔ±ÏԵúÜÅ£¡£
ÎÒ¸öÈ˵ÄÀí½â£¬Ö®ËùÒÔCºÍC++³ÌÐòÔ±ÏԵúÜÅ££¬ÆäʵÔÒòºÍ´ó¼ÒÏëÏñµÄÕýºÃÏà·´£¬²»ÊÇÒòΪCºÍC++̫ǿ´ó£¬¶øÊÇÕâ ......