Re: [luabind] How to adopt a boost::shared_ptr?
Brought to you by:
arvidn,
daniel_wallin
From: Leo Y. <sur...@ya...> - 2003-09-23 04:30:33
|
Hi, I have this cpp code: // cpp code begin class cTest; typedef boost::shared_ptr<cTest> TestPtr; class cTest { public: ~cTest() { printf( "%d released\n", _a ); } int _a; static TestPtr CreateSharedPtr( int a ) { TestPtr p( new cTest ); p->_a = a; return p; } static cTest* CreateRawPtr( int a ) { cTest *p = new cTest(); p->_a = a; return p; } }; // cpp code end Let's look the following script code: --- lua code begin --- t1 = CreateSharedPtr( 1 ) t2 = CreateRawPtr( 2 ) -- I want to release t2 here t2 = nil print( "Release t2 here" ) -- and release t1 here t1 = nil print( "Release t1 here" ) print( "over" ) --- lua code end --- The result was not what I expected. It turned out to be the following. Release t2 Release t1 over 2 released 1 released I supposed that '2 released' would appear before 'Release 2' and I could use the 'adopt' policy here to help me releasing t1. I thought I had made a mistake here. After I tested how lua collect the memory garbage, I think I must find another way to get 'release t1'. :) Thanks Daniel and Simon for your attention. Leo Yee --- Daniel Wallin <dal...@st...> wrote: > At 09:39 2003-09-19, Leo Yee wrote: > >Hi, Arvidn and Daniel! > > > >So quiet here recently. > > > >I have a question how to adopt a shared_ptr. What I > >mean is we can let the pointer reset when it go out > of > >scope. > > Sorry for the late reply. > > I don't really understand what you mean by this, > could you > clarify? Perhaps a code snippet would help. > > --- > Daniel Wallin > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com |