# How can I stop the Garbage Collector from removing a UTexture2D?

**URL:** <https://forums.unrealengine.com/t/how-can-i-stop-the-garbage-collector-from-removing-a-utexture2d/283918>\
**Category:** Asset Creation\
**Tags:** garbage-collector, unreal-engine, CPP, question\
**Created:** [May 21, 2014, 10:53pm UTC](https://forums.unrealengine.com/t/how-can-i-stop-the-garbage-collector-from-removing-a-utexture2d/283918 "2014-05-21T22:53:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![LennardF1989](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lennardf1989/32/555632_2.png) [@LennardF1989](https://forums.unrealengine.com/u/LennardF1989)\
**Post date:** [May 21, 2014, 10:53pm UTC](https://forums.unrealengine.com/t/how-can-i-stop-the-garbage-collector-from-removing-a-utexture2d/283918/2 "2014-05-21T22:53:18Z")

</div>

I have a C++ class not extending anything, it acts as a wrapper around a library, for use in Unreal Engine 4.

Initially I had the UTexture defined like this:

```
private:
     UTexture2D *Texture;

```

However, after creating the texture using `CreateTransient`, I noticed it got destroyed after 50-60 seconds. ■■■■… the garbage collector is at it.

I ended up fixing this by making it a UProperty, and after initializing the texture, calling AddToRoot.

But I was wondering, is this the only way? How come my initial way doesn’t count as “keeping a reference” even though the wrapper never “dies”?

---

_[View the full topic](https://forums.unrealengine.com/t/how-can-i-stop-the-garbage-collector-from-removing-a-utexture2d/283918)._
