Create a UIButton with (or without) memory

I am trying to add a UIButton with code (not Interface Builder).

Some examples say that you SHOULD allocate and free up memory for a button.

Others use buttonWithType and magically create a button without allocating any memory at all.

How is this possible?

(Both seem to be working fine.)

Which of the two methods do I want to use ... and when? Are there any huge advantages to this or that method?

PLEASE don't tell me to just “read the documents”. Documents are REASONS, I'm here. They rarely seem to explain things without leaving tons of "missing information."

+3
source share
3

buttonWithType: , autoreleased. , - released. , [UIButton buttonWithType:] [[[UIButton alloc] initWithFrame:] autorelease].

, , , .

+10

. +buttonWithType: - ,

[[[UIButton alloc] initWithType:type] autorelease];

-autorelease 'd, -release .

(, , ..) +buttonWithType:, . .

+2

Cocoa : autorelease.

Cocoa,

,

, , "alloc", "new", "copy" "mutableCopy" (, alloc, newObject mutableCopy).

buttonWithType , , , buttonWithType. , buttonWithType , autorelease, .

0

Source: https://habr.com/ru/post/1733216/


All Articles