# Blueprint node pins hold object references indefinitely

**URL:** <https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080>\
**Category:** Editor Scripting\
**Tags:** garbage-collector, reference, unreal-engine, memory, question, Blueprint\
**Created:** [August 3, 2017, 6:00am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080 "2017-08-03T06:00:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spoondog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Spoondog](https://forums.unrealengine.com/u/Spoondog)\
**Post date:** [August 3, 2017, 6:00am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/1 "2017-08-03T06:00:35Z")

</div>

Blueprint nodes with object pins will hold a reference to that object indefinitely (or until that branch of nodes is executed again or the object is destroyed).

This could potentially be keeping some huge objects in memory that are no longer in use.

I noticed this when the textures loaded in my widgets were still in memory even after replacing the references manually and garbage collecting. No doubt most blueprinters aren’t aware of this and could be e.g. spawning objects that execute nodes references to other objects… this could be eating memory all over the place.

e.g. if you have something like this in the construct event of your widget:

 ![203586-bpnodeobjref.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/7/f/47f465f05c0b10c82d7a2329602cb8a1b0f12bfd.png)

That texture we loaded temporarily will be referenced basically forever, even though we only needed it for a brief moment, because we can’t unload widgets in blueprint and that node doesn’t get executed again.

This was [reported by someone else before][2] but it was an old version, posted in an obscure category, and potentially quite a harmful issue, so I’ve made an updated thread.

As the poster in the original thread says, it seems like BP should be able to clear those references when the branch has finished executing. So next time a GC happens they should be gone.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9f47de28](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9f47de28](https://forums.unrealengine.com/u/anonymous_user_9f47de28)\
**Post date:** [August 3, 2017, 6:34am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/2 "2017-08-03T06:34:55Z")

</div>

So this doesn’t prevent, say, a character from getting destroyed- but anything which can’t be explicitly destroyed is kept in memory instead? Definitely explains some things I haven’t nailed down but have observed.

---

<div class="post-metadata">

**Author:** ![Spoondog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Spoondog](https://forums.unrealengine.com/u/Spoondog)\
**Post date:** [August 3, 2017, 6:43am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/3 "2017-08-03T06:43:56Z")

</div>

I think that is correct, yes.

---

<div class="post-metadata">

**Author:** ![ambershee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ambershee](https://forums.unrealengine.com/u/ambershee)\
**Post date:** [August 3, 2017, 7:39am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/4 "2017-08-03T07:39:23Z")

</div>

I duplicated this issue with the following:  
[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/f/2ff6a88f523e5bac9ccc5114139c23f5323a7c7e.png) ](https://snipboard.io/nFcgdz.jpg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9f47de28](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9f47de28](https://forums.unrealengine.com/u/anonymous_user_9f47de28)\
**Post date:** [August 3, 2017, 8:10am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/5 "2017-08-03T08:10:16Z")

</div>

Not sure the right solution is to clear the ref… Maybe instead of a hard reference these should be a weak ptr/ref. The event still retains the ptr and can reference the object, but if nothing else is referencing the object then it can be GC’d. Of course, if you don’t IsValid it, you can get a ‘Accessed Null’ error, but that problem happens anyway with Actors that get destroyed.

---

<div class="post-metadata">

**Author:** ![ambershee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ambershee](https://forums.unrealengine.com/u/ambershee)\
**Post date:** [August 3, 2017, 8:13am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/6 "2017-08-03T08:13:05Z")

</div>

That’s what it should be doing, I think.

---

<div class="post-metadata">

**Author:** ![Spoondog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Spoondog](https://forums.unrealengine.com/u/Spoondog)\
**Post date:** [August 7, 2017, 10:03pm UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/7 "2017-08-07T22:03:14Z")

</div>

Well looks like it might be fixed in 4.17 already (as far as the LoadAsset node goes):

“Assets that are only referenced by pins inside active Blueprints will now correctly be garbage collected. This means that if you use LoadAsset to load something and do not store it for future usage, it will no longer stay in memory forever until the loading Blueprint is destroyed”.

(Will mark as answer when I get around to testing it there)

---

<div class="post-metadata">

**Author:** ![Hyperloop](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hyperloop/32/1203427_2.png) [@Hyperloop](https://forums.unrealengine.com/u/Hyperloop)\
**Post date:** [January 12, 2018, 1:53am UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/8 "2018-01-12T01:53:30Z")

</div>

Can we get someone from epic to chime in on this please? This is a huge issue and I need to know if it has been addressed.

---

<div class="post-metadata">

**Author:** ![ArCorvus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ArCorvus](https://forums.unrealengine.com/u/ArCorvus)\
**Post date:** [June 28, 2018, 6:03pm UTC](https://forums.unrealengine.com/t/blueprint-node-pins-hold-object-references-indefinitely/401080/9 "2018-06-28T18:03:40Z")

</div>

still have this issue on 4.18.3 (Create Widget)
