2013年7月20日星期六

About alloc init

Why these two must be used in conjunction with it? alloc has been allocated for the object storage space, init is doing what? Generally in accordance with java run, new one after the object is not directly used?
------ solutions --------------------------------------- -----------------
alloc only allocate storage space, and no initialization, init there might be some way to do that, you can also write your own init method inside it, similar to the in the java constructor's content
------ solutions ------------------------------- -------------------------
c + + inside the new, will first allocate memory, then call the class constructor initializes this memory. So allocate memory and initialization work, new themselves have done. The new Java should also be similar to the first allocated memory, and then complete the initialization.

Cocoa inside alloc, from the name of view, should only allocate memory, init is responsible for initializing. alloc and init with the completion of the new work similar to Java.

I'm new to Objective-C, the feeling is so.
------ solutions --------------------------------------- -----------------
alloc is to allocate memory space, init is initialized, the two together is equivalent to the new, where the OC can be used, but generally recommended using alloc + init, this can more clearly see the memory allocation and initialization of the process, and if there is such initWith ...... init method on the convenience of these points
------ solutions - -------------------------------------------------- ----
alloc only allocates memory space for object, the object is initialized init method.
------ solutions -------------------------------------------------- ------
[NSObject new]

没有评论:

发表评论