개발자의 사투

델파이 객체 자동 Free 본문

컴방/델파이

델파이 객체 자동 Free

개발자룽 2020. 1. 14. 15:51

shared_ptr 개요(한글) : http://egloos.zum.com/sweeper/v/2826435

델파이 shared_ptr(git)
https://github.com/arafangion/delphisharedpointer


델파이 smartPointer
https://en.delphipraxis.net/topic/402-smart-pointers-generics-vrs-non-generic-implementastion/
https://github.com/marcocantu/DelphiSessions/blob/master/DelphiLanguageCodeRage2018/02_SmartPointers/SmartPointerClass.pas


=========================== 추가 참고 ===========================
간단한 Guard (객체 자동 Free)
http://www.delmadang.com/community/bbs_view.asp?bbsNo=3&bbsCat=0&st=S&keyword=guard&indx=196963&keyword1=guard&keyword2=&page=1

델파이판 AutoPtr
http://www.borlandforum.com/impboard/impboard.dll?action=read&db=component&no=557

 

 

해당글들을 참고하였고

https://github.com/arafangion/delphisharedpointer 최종 해당글을 사용하였습니다.

var

    FSmartPointTest: TShared;

begin

  FSmartPointTest.Create(TStringList.Create);

  FSmartPointTest.Temporary.Add('aaaaa');
  FSmartPointTest.Temporary.Add('bbbb');

  ShowMessage(FSmartPointTest.Temporary.Text);

end;

 

간단한 테스트를 마침.

 

Free사용을 안해도 메모리릭오류 발생 x

 

 

 

단점은...

Some limitations that I could not resolve with Delphi:

  • There is no way to mark the shared pointer as invalid - the developer, once the smart pointer has been released, must take care not to use the reference again, otherwise a runtime error will result. (Internally, the reference is nil'ed, but it is not a compiler error to attempt to use it).
  • There is no way to overload the 'dot operator', similar to how smart pointers are done in C++. This does have the impact of making effective use of the shared pointer considerably more tedious.
  • Destruction order is undefined. Hopefully this is not a problem, however, if it is a problem, then it will be recommended to .Release.Free the pointer manually, as appropriate, in a try/finally block.

보는바와같다....

Comments