Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[weak self] #5

Closed
Brandnew-one opened this issue Apr 21, 2022 · 0 comments
Closed

[weak self] #5

Brandnew-one opened this issue Apr 21, 2022 · 0 comments

Comments

@Brandnew-one
Copy link
Owner

weak self 에 대하여 - 1

간략하고 이해한 내용 위주로 간단하게 정리하고 주말에 예제코드와 함께 더 상세히 작성해보겠습니다!

참고하면 좋을 WWDC21 참고하기
참고하면 좋을 블로그

Swift는 ARC를 통해서 객체에 대한 참조 카운트를 관리하고 0이 되면 자동으로 메모리를 해제 해주는 기능을 가지고 있다.
하지만 두개 이상의 객체가 서로에 대한 강한 참조를 가지면 순환참조가 발생하게 돼서 메모리 누수 현상이 일어나게 됩니다.

이런 현상을 막기 위해서 우리는 weak를 사용합니다.

일반적으로 탈출 클로저에서 [weak self]를 자주 접하게 됩니다. 탈출 클로저에서 값을 캡처하는 과정에 명시적으로 self를 작성해줘야 하는데 이때 self에 대한 순환참조가 발생할 수 있기 때문입니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant