Opened 13 years ago
Closed 13 years ago
#3412 closed Bugs (fixed)
Memory leak in BOOST_CLASS_EXPORT registration
| Reported by: | Owned by: | Robert Ramey | |
|---|---|---|---|
| Milestone: | Boost 1.41.0 | Component: | serialization |
| Version: | Boost 1.41.0 | Severity: | Problem |
| Keywords: | serialization memory leak | Cc: |
Description
Added example of code that will give memory leak. The code is tested with MSVC-8.0. When run in debug the program will show three memory leaks. If I set a break point in the void_caster_shortcut constructor the function is run once, but the destructor is never called.
#include <stdio.h>
#include <tchar.h>
#include <crtdbg.h>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/export.hpp>
class Base {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) { }
virtual void vTest() { }
};
class Level1 : public Base {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{ ar & boost::serialization::base_object<Base>(*this); }
};
class Level2 : public Level1 {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{ ar & boost::serialization::base_object<Level1>(*this); }
};
BOOST_CLASS_EXPORT(Base)
BOOST_CLASS_EXPORT(Level1)
BOOST_CLASS_EXPORT(Level2)
int _tmain(int argc, _TCHAR* argv[])
{
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
return 0;
}
Attachments (1)
Change History (5)
comment:1 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
by , 13 years ago
| Attachment: | MemLeakSerialization.cpp added |
|---|
comment:2 by , 13 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
| Version: | Boost 1.40.0 → Boost 1.41.0 |
Some of the memory leaks are gone, but there are still some memory leaks left in the registration code. I have updated the example with Level3 and Level4 and get new leaks. See attached file. To make the code easier to debug it is possible to comment out BOOST_CLASS_EXPORT(Level4). Then you only get one leak.
comment:3 by , 13 years ago
I've found this and fixed on my own machine. It will be checked into the trunk shortly.
I don't think I could have tracked this down without your test.
Robert Ramey
comment:4 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |

I've fixed this on my own machine.
I don't know if it will get uploaded/tested in time for inclusion in 1.41.
Thanks for providing a good test case. It was very helpful.
Robert Ramey