# Does Unreal detroy childrens upon parent destruction?

**URL:** <https://forums.unrealengine.com/t/does-unreal-detroy-childrens-upon-parent-destruction/373905>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 20, 2016, 12:00pm UTC](https://forums.unrealengine.com/t/does-unreal-detroy-childrens-upon-parent-destruction/373905 "2016-10-20T12:00:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gamer08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamer08](https://forums.unrealengine.com/u/gamer08)\
**Post date:** [October 20, 2016, 12:00pm UTC](https://forums.unrealengine.com/t/does-unreal-detroy-childrens-upon-parent-destruction/373905/1 "2016-10-20T12:00:11Z")

</div>

Hello Guys,

I’m still working on memory management for our game and I wonder something.

**Does Unreal is supposed to destroy automatically`UPROPERTY()`marked childrens objects (Actor or Object) pointers upon their destruction ?**

Consider the folowing code :

**.h**

```
class AGame_API ADummyActor : public AActor
{
	GENERATED_BODY()
	
public:

	ADummyActor(const FObjectInitializer& ObjectInitializer);

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Dummy)
	UTexture* texture;

    void SetTexture();
};

```

**.cpp**

```
ADummyActor::ADummyActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	texture = nullptr;
}

void ADummyActor::SetTexture()
{
	texture = LoadObject<UTexture>(this, TEXT("/Game/Menu/Artwork/toto/Background_fantasy.Background_fantasy"), NULL, LOAD_None, NULL);
}

```

This code would be the same for a UObject derived object.

For this case, assume that I no (0) instance of the DummyActor and I have a button to spawn an instance and another to destroy that very same instance. Also, assume that the texture is not referenced anywhere else.

When I call delete upon the button, is it supposed to also destroy the texture pointer and release the memory associated with the texture ?

**If YES, that doesn’t work at all.**

**If NO, should I declare a ClearChildrens function that will manually delet every childrens data ? or what sould I do ?**

I mean in raw C++ there’s no garbage, so I’m well used to clean childrens memory upon destructor call.

But with Unreal, we are supposed to have a garbage collector that is supposed to clean unused memory right ?

Or am I crazy and missed something o0 ?

Thanks for any help…

gamer08

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_210522a1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_210522a1](https://forums.unrealengine.com/u/anonymous_user_210522a1)\
**Post date:** [October 20, 2016, 2:45pm UTC](https://forums.unrealengine.com/t/does-unreal-detroy-childrens-upon-parent-destruction/373905/2 "2016-10-20T14:45:07Z")

</div>

As far a I know Unreal doens’t destruct children on destruction of a parent since you can have children in a Level without a parent in the level. But I am not sure

---

<div class="post-metadata">

**Author:** ![gamer08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamer08](https://forums.unrealengine.com/u/gamer08)\
**Post date:** [October 20, 2016, 3:04pm UTC](https://forums.unrealengine.com/t/does-unreal-detroy-childrens-upon-parent-destruction/373905/3 "2016-10-20T15:04:05Z")

</div>

Hello ,

Well, it’s something I would to have a confirmation from epic staff if possible because it’s not very clear on the documentation.

---

<div class="post-metadata">

**Author:** ![gamer08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamer08](https://forums.unrealengine.com/u/gamer08)\
**Post date:** [October 21, 2016, 11:18am UTC](https://forums.unrealengine.com/t/does-unreal-detroy-childrens-upon-parent-destruction/373905/4 "2016-10-21T11:18:07Z")

</div>

Hey guys,

I decided to call up a function to “clear childrens” before delete the parent and this with both actor and object. In the end it works, but I would really like to know if the GC is suppose to clear childrens automatically upon parent destruction specifically if they are marked `UPROPERTY()` ?

Thanks for a future answer.

gamer08
