■ ReferenceType 클래스를 사용해 약한 참조를 만드는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import weakref class Apple: pass apple1 = Apple() apple1.Color = "빨강" weakref1 = weakref.ReferenceType(apple1) # ref 별칭을 사용할 수 있다. apple2 = weakref1() print(apple2.Color) # 빨강 print(apple1 is apple2) # True, 두 객체는 동일하다. |