Skip to content

Commit

Permalink
TTValue: when a value (an element, actually) is freed, and that eleme…
Browse files Browse the repository at this point in the history
…nt is a dictionary, no longer leak it. see #123.
  • Loading branch information
+1m place committed Jul 2, 2013
1 parent ad9015b commit 612aded
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Foundation/library/includes/TTDictionary.h
Expand Up @@ -85,6 +85,14 @@ class TTFOUNDATION_EXPORT TTDictionary {
}


TTDictionary(TTElement* do_not_use_this_unless_your_name_is_ttelement_and_you_are_a_destructor)
{
mName = TTSymbol(do_not_use_this_unless_your_name_is_ttelement_and_you_are_a_destructor->mValue.dictionary);
mDictionaryInstance = gTTDictionaryTable[mName.rawpointer()];
// DO NOT INCREASE THE REFERENCE COUNT -- THIS IS A SPECIAL CONSTRUCTOR USED FOR TTELEMENT'S DESTRUCTOR
}


/** Copy Constructor */
TTDictionary(const TTDictionary& aSourceDictionary)
{
Expand Down
3 changes: 3 additions & 0 deletions Foundation/library/includes/TTElement.h
Expand Up @@ -120,6 +120,7 @@ break;\


class TTFOUNDATION_EXPORT TTElement {
friend class TTDictionary;

/** The data value of TTValue is stored using a union. */
union TTDataValue {
Expand Down Expand Up @@ -166,6 +167,8 @@ class TTFOUNDATION_EXPORT TTElement {
// {
// *this = anInitialValue;
// }

virtual ~TTElement();


/** query an element for its type */
Expand Down
9 changes: 9 additions & 0 deletions Foundation/library/source/TTValue.cpp
Expand Up @@ -46,6 +46,15 @@ void TTValue::clear()
#endif


TTElement::~TTElement()
{
if (mType == kTypeDictionary) {
TTDictionary d(this); // when d goes out of scope the refcount will decrease and the dictionary will be potentially freed.
}
// TODO: need special handling for strings also?
}


TTElement::operator TTDictionary() const
{
if (mType == kTypeDictionary) {
Expand Down

0 comments on commit 612aded

Please sign in to comment.