아래 코드는 jellybean의 surfaceflinger test code의 일부분이다.
sp<Surface> surface = Surface::readFromParcel(parcel);
ANativeWindow* window = surface.get();
readFromParcel( 꾸러미에서 읽다 ) 를 사용하는 것으로 보아 binder를 사용하여 무언가를 얻어왔을 것이고
sp<Surface> 로 보아 Surface를 요청한 것 같다.
Parcel 안에는 binder같은게 들어있으니..
안드로이드의 대부분의 코드를 보다보면 sp, wp 를 사용한 포인터를 정말 자주 볼 수 있다.
또한 Surface 클래스에는 get이라는 함수가 없다.
[reference 1] http://weblogs.java.net/blog/2006/05/04/understanding-weak-references
[reference 2] http://blog.naver.com/atonikkaz/10013450090
Strong Pointer
in/decrease refer count to use memory leak.
strong reference : use NEW keword
Week Pointer
no in/decrease ref count
Weak reference에 의해 참조된 객체는 garbage collection이 발생하기 전까지는 객체에 대한 참조를 유지하지만 일단 garbage collection이 발생하면 무조건 수거된다. Weak reference가 사라지는 조건은 garbage collection의 실행 주기와 일치하는 것이다. 이를 이용하면 짧은 시간 동안 자주 쓰일 수 있는 객체를 캐쉬할 때 유용하게 이용할 수 있다
sp, wp를 사용하겠다는 이야기는..
garbage collection의 개념이 들어간거고..
(자의적 해석이므로 오해의 소지가 있다...)\
문제의 get은 여기에 있다..
==============================
frameworks/native/include/utils/RefBase.h
==============================
template <typename T>
class wp
{
// promotion to sp
sp<T> promote() const;
}
==============================
frameworks/native/include/utils/StrongPointer.h
==============================
template <typename T>
class sp
{
inline T* get() const { return m_ptr;}
WP.promote => WP -> SP 변환
결론적으로..
ANativeWindow* window = surface.get();
음..surface 포인터를 ANativeWindow* 로 캐스팅..
*bonus
onFirstRef() called in RefBase::incStrong!!
sp<Surface> surface = Surface::readFromParcel(parcel);
ANativeWindow* window = surface.get();
readFromParcel( 꾸러미에서 읽다 ) 를 사용하는 것으로 보아 binder를 사용하여 무언가를 얻어왔을 것이고
sp<Surface> 로 보아 Surface를 요청한 것 같다.
Parcel 안에는 binder같은게 들어있으니..
안드로이드의 대부분의 코드를 보다보면 sp, wp 를 사용한 포인터를 정말 자주 볼 수 있다.
또한 Surface 클래스에는 get이라는 함수가 없다.
[reference 1] http://weblogs.java.net/blog/2006/05/04/understanding-weak-references
[reference 2] http://blog.naver.com/atonikkaz/10013450090
Strong Pointer
in/decrease refer count to use memory leak.
strong reference : use NEW keword
Week Pointer
no in/decrease ref count
Weak reference에 의해 참조된 객체는 garbage collection이 발생하기 전까지는 객체에 대한 참조를 유지하지만 일단 garbage collection이 발생하면 무조건 수거된다. Weak reference가 사라지는 조건은 garbage collection의 실행 주기와 일치하는 것이다. 이를 이용하면 짧은 시간 동안 자주 쓰일 수 있는 객체를 캐쉬할 때 유용하게 이용할 수 있다
sp, wp를 사용하겠다는 이야기는..
garbage collection의 개념이 들어간거고..
(자의적 해석이므로 오해의 소지가 있다...)\
문제의 get은 여기에 있다..
==============================
frameworks/native/include/utils/RefBase.h
==============================
template <typename T>
class wp
{
// promotion to sp
sp<T> promote() const;
}
==============================
frameworks/native/include/utils/StrongPointer.h
==============================
template <typename T>
class sp
{
inline T* get() const { return m_ptr;}
WP.promote => WP -> SP 변환
결론적으로..
ANativeWindow* window = surface.get();
음..surface 포인터를 ANativeWindow* 로 캐스팅..
*bonus
onFirstRef() called in RefBase::incStrong!!




최근 덧글