Collections in external SDK
Aug 12, 2013 at 4:22am
Collections in external SDK
Some questions , maybe any of you experts could help a newbie :) My external is working properly, jut i’m not sure if i cause some memoryleaks with it or not :D
1, If I’m the owner (“noun”) of the dictionary object and I “dictionary_clear(dict)” it, it says in the documentation: “This method will free the objects in the dictionary.” Is this mean all included “subdictionaries” appended to it will get a “object_free(subdict)” so those will be unregistered and the memory of the subdicts will be freed up too? No need to handle them by myself?
2, If (1) is true, then should i call “dictionary_clear()” before “object_free(dict)“? or “object_free(dict)” will clear it’s subdictionary contect by itself?
3, If (1) is true and all I want to do is to create and output a dictionary with subdictionaries inside my object, then should i keep track the subdictionary pointers and names, or if they are registered and appended to the main (“dictionary_appenddictionary()“) they will be deleted automatically when i send “dictionary_clear()” or “object_free(dict)” to the main dictionary?
thanx for your help in advance!
Aug 12, 2013 at 8:36am
(AFAIK && sdk 5.1.7)
1. True: Sd(s) will be freed automatically and recursively.
The dictionary behavior is explained here ( http://cycling74.com/sdk/MaxSDK-6.0.4/html/group__dictionary.html ).
To resume: soon as you appended a dictionary inside another dictionary, you also transfer ownership. If you want to avoid that the main dictionary frees the contained dictionary, you need to chuck it before the release.
Aug 12, 2013 at 9:45am
thanx Nicolas, i was using the pdf version of the API documentation… but it seems it’s a bit different to the html version so maybe the html can clear up some things for me :)
Regarding (3) i just meant the main dictionary object (owned by my external) will be cleared and filled up with new values on every bang and send out the name on an outlet. I was wondering if I create and append a new dictionary to the main dict, then I guess I don’t need to track the name and pointer to that, as it will be freed automaticly when the main dictionary will be freed or cleared. I guess this “soon as you appended a dictionary inside another dictionary, you also transfer ownership.” means exactly that, i don’t need to save the pointers and names if i don’t need them, as the main dictionary will be free them…
thanx again Nicolas, loving your github collection of helpers!
Aug 12, 2013 at 10:30am
1. Yep, i guess you don’t have to care about. But i can not affirm that. Passing dictionaries is a Max 6 ( http://cycling74.com/sdk/MaxSDK-6.0.4/html/group__dictobj.html ) feature that i’m not aware. Somebody could confirm ?
2. Thanks. It remains bunch of questions not resolved by reading through the examples provided in the SDK. So i started to collect responses on the forum in a kind of FAQ. Of course, a MaxForge with dozens of volunteers may produce much more quality codes with parts about DSP / Jitter / 64 bits How to / etc. ;-)
You must be logged in to reply to this topic.