# OwnedArray / base class pointers

**URL:** <https://forum.juce.com/t/ownedarray-base-class-pointers/1195>\
**Category:** General JUCE discussion\
**Created:** [November 5, 2006, 3:36pm UTC](https://forum.juce.com/t/ownedarray-base-class-pointers/1195 "2006-11-05T15:36:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [November 5, 2006, 3:36pm UTC](https://forum.juce.com/t/ownedarray-base-class-pointers/1195/1 "2006-11-05T15:36:40Z")

</div>

Okay, i’m cool with having virtual destructors so that an array of pointers to a base type is able to happily delete subclassed type objects.

But i’m a little wary of using OwnedArray - for now i’m using an Array of the base type, and when removing an object i delete it then remove the pointer from the array. Logically i assume OwnedArray will be fine, but i wasn’t sure if it did some internal magic using the size of the specified type (i.e. a subclass object will have more data in it than the base object and thus be bigger). Is this not actually a problem for OwnedArray? I’d like to leave the array to do the deleting for me, but of course i’m just a little concerned that it may not like being given subclass type objects.

---

<div class="post-metadata">

**Author:** ![daniel78](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@daniel78](https://forum.juce.com/u/daniel78)\
**Post date:** [November 5, 2006, 7:24pm UTC](https://forum.juce.com/t/ownedarray-base-class-pointers/1195/2 "2006-11-05T19:24:19Z")

</div>

i’m pretty sure an ownedarray only stores pointers to objects, so the size of the data isn’t an issue. Or am i misunderstanding the question?

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [November 5, 2006, 11:47pm UTC](https://forum.juce.com/t/ownedarray-base-class-pointers/1195/3 "2006-11-05T23:47:55Z")

</div>

yeah, that’s what i thought. i just wanted to make absolutely sure it was safe to do - i wasn’t sure if it did any special extra hidden memory management stuff behind the scenes… but thinking about it that would be pretty bad anyway!

i was just a bit paranoid. it was a bit of a stupid question really.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 6, 2006, 9:39am UTC](https://forum.juce.com/t/ownedarray-base-class-pointers/1195/4 "2006-11-06T09:39:00Z")

</div>

Yes, it’s absolutely fine to let the OwnedArray mange and delete any subclass of the base class you specify, (as long as your class has a virtual destructor, of course).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:59am UTC](https://forum.juce.com/t/ownedarray-base-class-pointers/1195/5 "2017-05-12T09:59:24Z")

</div>

Closed on May 12, 2017, 9:59am UTC


