Is the memory address of the object stored throughout its life?

I am not sure that the memory address of the object remains unchanged throughout its life. Does it have? Or does it sometimes change during the existence of an object?

+4
source share
4 answers

Yes, the address of any given object is constant in Objective-C. This is pretty important because objects are always referenced at. :-) (Garbage collectors that move things and update all pointers to them exist, but garbage collection is not supported on the iPhone, and the Obj-C Mac garbage collector is not documented for this - see Garbage Collector Programming Guide: Architecture , under “How the Garbage Collector Works”.

+5
source

If you mean self , then yes, it remains intact throughout the entire life cycle of the object.

0
source

Although I did not stand on this issue, my views are as follows:

The memory addresses of an object may not be static.

For example, in Java, objects do not have pointers, and links, the virtual machine can move around objects as part of its memory management scheme and can change the value of the link in accordance with the moved object. Objects can also be moved as part of the JVM garbage collection process.

Although I have not read any official documentation about this, if you come across this, you can post it here.

The same process can occur in .Net.

-1
source

In the Cocoa Garbage Collection Programming Guide, I do not see the convincing certainty that Ahruman does above, that the address of the object is guaranteed to be constant:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcArchitecture.html

Section "Closed and open systems":

'[In an open garbage collection system, collectors] redistribute and copy blocks of memory and update each link pointer to reflect the new address. [...] Cocoa the garbage collector strikes a balance between “closed” and “open”, knowing exactly where the pointers to scanned blocks are located anywhere, easily tracking “external” links and being “conservative” only where it should. ''

And with the general “dynamic” nature of Cocoa's runtime, I would like an explicit discussion of the subject in Apple documentation even for a non-garbage-related program. I don’t find any claim that “the object’s memory address is guaranteed to not change” when searching the entire developer.apple.com site - try Google with

 site:developer.apple.com cocoa "object memory address" OR "memory address of an object" guaranteed OR permanent 

And there is this terrible thing ... multithreading (ahhhh).

-1
source

All Articles