■ proxy 함수를 사용해 dict 객체를 위한 약한 참조 프록시를 만드는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import weakref # 리스트, 딕셔너리 같은 내장 타입에 대한 약한 참조 객체를 만들 경우 서브 클래싱을 이용한다. class CustomDictionary(dict): pass dictionary1 = CustomDictionary() dictionary1["apple" ] = 100 dictionary1["orange"] = 300 weakProxy1 = weakref.proxy(dictionary1) print(weakProxy1["apple"]) |