IOS ARC with JAVA garbage collection,

Source: Internet
Author: User

Same:

1, the final result is to release the unnecessary space,

Different:

Assign (weak): Direct assignment

Retain (strong): +1, refer once to call once retain

Release:-1

Copy: Two variables do not share memory, each has its own memory

Atomic: Atomic operation (used when multi-threading)

Nonatomic: Non-atomic operation

@autorelease Pool: Maintaining a reference pond

A. Create a autorelease pool first
B. The object is generated from within this autorelease pool.
C. After the object is generated, call the Autorelease function, which simply marks the Autorelease pool and lets the pool remember to release the object in the future.
D. At the end of the program, the pool itself needs to be rerlease, and the pool will release each object marked as Autorelease once. if an object retain count is greater than 1 at this point, the object is still not destroyed .
The above example should be written like this:
ClassName *myname = [[[ClassName alloc] init] autorelease];//marked as Autorelease
[ClassA Setname:myname]; Retain count = = 2
[MyName release]; Retain Count==1, note that in ClassA Dealloc cannot release name, otherwise the release pool will release this retain count 0 object, this is not right.

Remember one point: If this object is your alloc or new, you need to call release. If you use Autorelease, release only once the retain has occurred ( let retain count is always 1).

ARC:

1, is the compile time, inserted into the code, Release,retain,

2, the scope of the management of different sizes, ARC of C code, the core Foundation code does not have jurisdiction over the rights

3, when we pass objects between the C function of the core foundation and the Objective-c method of the foundation kit, it is often necessary to do an ID and void* two types of cross-transfer. If you use arc, you must tell the compiler with a hint/qualifier when the CF object enters and is out of control of the arc. Qualifiers are __bridge, __bridge_retain, and __bridge_transfer. In addition, you still need to use Cfretain and cfrelease to manage the objects of the core Foundation.

Java:

1, is the run time, also run a special cleaning tool, when the reference is 0 to free up space . There is also a graph of the traversal, can not reach,

2, all objects are managed

Comprehensive: It can be understood that arc is part of the garbage collection PS: Welcome to discuss communication,

Add:

Java memory allocation, mainly divided into 4 blocks!
A piece is used to put code, that is, to compile something.
A piece is used to install static variables, such as variables with the static keyword, such as String constants.
A stack, or stack, is used to load variables and reference types! But the difference is that after the variable is loaded, there is a value on the variable, and the reference type itself has no value on the stack.
A heap, that is, heaps! Heap can be summed up in a word, loaded new things!

All in all: the base data type is in the stack, and the reference type, the variable is placed in the stack, and the real content is placed in the heap, that is, when new is introduced into the heap, the reference type variable in the stack points to the heap of your new out!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.