해결된 질문
작성
·
126
0
5강 마지막에 보면 인터페이스 최적화를 위해 이렇게 구현을 하셨는데요...
public static Managers Instance { get { Init(); return s_instance; } } // 유일한 매니저를 갖고 온다
아래처럼 에러가 나고 있습니다. 마치 무한히 재귀호출이 일어나는 것처럼 보이는데... 그래서 Init(); 호출을 지우면 이런 오류는 안나옵니다. 무한 호출이 일어나는 이유를 알 수 있을까요?
StackOverflowException: The requested operation caused a stack overflow. Managers.get_Instance () <0x252b47f87f0 + 0x00008> in <3152d6b1a9334587bbe43f1d8528b776>:0 Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.Init () (at Assets/Scripts/Managers/Managers.cs:25) Managers.get_Instance () (at Assets/Scripts/Managers/Managers.cs:8) Managers.In<message truncated>
답변 2
0
0
위 내용만으로는 알 수 없고
Init() 코드 내부가 관건입니다.
public static Managers Instance { get { Init(); return s_instance; } }
작성하신 코드에서 Instance 내부에서 Init()을 호출하는데,
Init() 내부에서는 다시 Instance를 사용할 것으로 예상됩니다.
Init -> Instance -> Init -> Instance -> ...
이렇게 무한으로 호출하다 보니
함수 호출을 위한 스택 메모리가 고갈되어 발생하는 것입니다.
따라서 Init 내부에서는 Instance를 사용하면 안되고, s_instance를 사용해야
해당 문제를 우회할 수 있습니다.