# UTexture2d deletion

**URL:** <https://forums.unrealengine.com/t/utexture2d-deletion/411798>\
**Category:** Asset Creation\
**Tags:** garbage-collection, unreal-engine, question\
**Created:** [December 9, 2017, 3:14am UTC](https://forums.unrealengine.com/t/utexture2d-deletion/411798 "2017-12-09T03:14:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_60c9dc7d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_60c9dc7d](https://forums.unrealengine.com/u/anonymous_user_60c9dc7d)\
**Post date:** [December 9, 2017, 3:14am UTC](https://forums.unrealengine.com/t/utexture2d-deletion/411798/1 "2017-12-09T03:14:02Z")

</div>

I create my texture using the following line

```
LoadedT2D = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight());

```

And it loads correctly. LoadedT2D is stored in a UProperty(). So as long as the class which holds this UProperty() lives this texture should live. But in my case this texture is never getting destroyed even when the class which holds the UProperty is destroyed (destructor is called).

When I used Rama’s tutorial ([A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums](https://wiki.unrealengine.com/Garbage_Collection_~_Count_References_To_Any_Object#Code)) to print out the references. It prints out `AssetImportData` and this is printed right after I create my texture with CreateTransient(). How do I avoid this reference to delete my texture.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6d61ec40](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6d61ec40](https://forums.unrealengine.com/u/anonymous_user_6d61ec40)\
**Post date:** [June 23, 2020, 10:38am UTC](https://forums.unrealengine.com/t/utexture2d-deletion/411798/2 "2020-06-23T10:38:44Z")

</div>

Hello,

I was having the same issue. The solution that seems to work is running RemoveFromRoot and ConditionalBeginDestroy manually on the texture that you want to deallocate. The GarbageCollector will take care of it in this case.

```
UCLASS(Blueprintable)
class UMyClass: public UObject
{
	GENERATED_BODY()
...

	UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = Default)
	UTexture2D *SelectionTexture = nullptr;
}
...

void UMyClass::ClearSelectionTexture()
{
	if (nullptr != SelectionTexture)
	{
		SelectionTexture->RemoveFromRoot();
		SelectionTexture->ConditionalBeginDestroy();
	}

	SelectionTexture = nullptr;
}

```
