1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Use weak_ptr for TypeDescriptor cross-links. Fixed total TypeDescriptor memory leak.

This commit is contained in:
AlexVinS 2016-08-30 09:47:33 +03:00
parent c6d257f328
commit a50a32405d
2 changed files with 5 additions and 2 deletions

View File

@ -474,8 +474,10 @@ std::vector<CTypeList::TypeInfoPtr> CTypeList::castSequence(TypeInfoPtr from, Ty
{
auto typeNode = q.front();
q.pop();
for(auto &nodeBase : upcast ? typeNode->parents : typeNode->children)
for(auto & weakNode : (upcast ? typeNode->parents : typeNode->children) )
{
auto nodeBase = weakNode.lock();
if(!previous.count(nodeBase))
{
previous[nodeBase] = typeNode;

View File

@ -156,11 +156,12 @@ class DLL_LINKAGE CTypeList: public boost::noncopyable
public:
struct TypeDescriptor;
typedef std::shared_ptr<TypeDescriptor> TypeInfoPtr;
typedef std::weak_ptr<TypeDescriptor> WeakTypeInfoPtr;
struct TypeDescriptor
{
ui16 typeID;
const char *name;
std::vector<TypeInfoPtr> children, parents;
std::vector<WeakTypeInfoPtr> children, parents;
};
typedef boost::shared_mutex TMutex;
typedef boost::unique_lock<TMutex> TUniqueLock;