Skip to content

Retain Count 방식에 대해 설명하시오. #8

Open
@heerucan

Description

@heerucan
No description provided.

Activity

hyesuuou

hyesuuou commented on Oct 1, 2021

@hyesuuou
Member

retain count 방식은 MRC 환경에서 reference count를 관리하는 것을 말한다. .retainCount 코드로 retain Count에 접근할 수 있다.
retain count는 인스턴스를 생성하거나, retain메서드를 사용할 때 +1만큼 증가한다. 인스턴스를 생성할때는 자동적으로 rc가 증가하지만, 이외의 경우에는 retain을 꼭 명시해주어 수동으로 + 1 해줘야 한다. 반대로 release를 사용하면 retain count가 -1 만큼 줄어든다.

(MRC 방식에서 쓰이기에 스위프트 언어로 개발할때는 쓰이지 않음! -> Swift는 ARC로 자동으로 관리되기 때문에)

Taehyeon-Kim

Taehyeon-Kim commented on Oct 10, 2021

@Taehyeon-Kim
Contributor

ARC가 등장하기 전에는 모든 객체의 레퍼런스 카운트를 직접 관리해야 하는 MRC 방식을 사용했다.

여기서 사용되는 개념인 Retain Count는 레퍼런스 카운트를 증가시킨다는 개념이고, 이와 반대되는 개념에는 Release Count는 레퍼런스 카운트를 감소시킨다는 개념이다.

Objective-C에서 다음과 같이 메서드를 사용할 수 있다.

TestClass *test = [[TestClass alloc] init];
[test retain]; // retain 메서드 사용
[test release]; // release 메서드 사용
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Taehyeon-Kim@heerucan@hyesuuou

        Issue actions

          Retain Count 방식에 대해 설명하시오. · Issue #8 · SwiftFrequency/iOSInterview