Problem with DeleteObj() and maxon::PointerArray
-
I'm workinig on a c++ plugin in R18 on Mac with Xcode. When I create a new maxon::PointerArray<customtype> with NewObj() in GetVirtualObjects, everything is working great. The problem is when I go to free the pointer array with DeleteObj() after i'm done with it I get a EXC_BAD_ACCESS.
My question is, how do I free up this array? Do I need too, or does the auto memory management take care of it when it falls out of scope? It is local in my GetVirtualObjects method.
Thanks!
-
Hello,
can you share some code to show that you are actually doing? Are you allocating the array or the objects stored in the array? If the array is a local variable, you can simply create in on the stack.
I haven't tried R18 (only have R20 currently available).
A
PointerArray
takes ownership of the stored objects. So it should not be needed to delete the objects manually. The objects are freed when the array is freed or reset.You find an example (for R20) in the Arrays Manual.
best wishes,
Sebastian -
Ahhhh thanks! I couldn't find an Array Manual in the R18 documentation.
I was going like this:
maxon::PointerArray<MyCustomClass> myPointerArr = NewObj(maxon::PointerArray<MyCustomClass>); DoStuffWithArray(myPointerArr); DeleteObj(myPointerArr);
It seems my problem was with the PointerArray taking ownership of my pointers, then deallocating them before I was done with them. Since it doesn't seem that R18 has
maxon::UniqueRef
objects I decided to go with amaxon::BaseArray<MyCustomClass*>
instead.Thanks again for your help Sebastian!