Looks like something is wrong over here.
If I check for memory leak using valgrind on Linux (or Boundschecker on
Windows) I get memory leak with below given code.
Here is some info on the same,
******************************************
==6794== 80 bytes in 1 blocks are definitely lost in loss record 8 of 11
==6794== at 0x40219DC: operator new(unsigned) (in
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==6794== by 0x804C1AB:
boost::archive::detail::basic_oarchive::basic_oarchive() (in
/home/sameer/work/a.out)
==6794== by 0x804BF84:
boost::archive::detail::common_oarchiveboost::archive::text_oarchive::common_oarchive()
(in /home/sameer/work/a.out)
==6794== by 0x804BFAC:
boost::archive::basic_text_oarchiveboost::archive::text_oarchive::basic_text_oarchive()
(in /home/sameer/work/a.out)
==6794== by 0x804BFFC:
boost::archive::text_oarchive_implboost::archive::text_oarchive::text_oarchive_impl(std::ostream&,
unsigned) (in /home/sameer/work/a.out)
==6794== by 0x804C08E:
boost::archive::detail::polymorphic_oarchive_impl
::polymorphic_oarchive_impl
&, unsigned) (in /home/sameer/work/a.out) ==6794== by 0x8049B5A: func(std::basic_stringstream &, boost::archive::polymorphic_oarchive*&) (in /home/sameer/work/a.out) ==6794== by 0x8049BE0: main (in /home/sameer/work/a.out)
But if I modify below given code as given below then it doesn't show any
memory leak.
I am using boost 1.32.
***********************************
changed code
**********************************
9 boost::archive::polymorphic_oarchive *ptr = NULL;
10 func(ss, ptr);
11 /* delete ptr; //Will this delete object properly????? */
boost::archive::polymorphic_text_oarchive *p =
dynamic_castboost::archive::polymorphic_text_oarchive*(ptr);
delete p; //Deleted after NULL check
**********************************
Thanks,
Sameer
On 12/2/08, Steven Watanabe
AMDG
sam p wrote:
I am using polymorphic archive in my code and I am using it as follows, 1 void func(std::stringstream &ss, boost::archive::polymorphic_oarchive *&ptr) 2 { 3 ptr = new boost::archive::polymorphic_text_oarchive(ss); 4 return; 5 } 6 int main() 7 { 8 std::stringstream ss; 9 boost::archive::polymorphic_oarchive *ptr = NULL; 10 func(ss, ptr); 11 delete ptr; //Will this delete object properly????? 12 } Now the question is, whether 'delete' one line no. 11 will work properly or not? And is this a right way to use polymorphic archive?
Yes. polymorphic_oarchive has a virtual destructor.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users