# TSharedRef for interface

**URL:** <https://forums.unrealengine.com/t/tsharedref-for-interface/474068>\
**Category:** UI\
**Tags:** interfaces, unreal-engine, Code, question, CPP\
**Created:** [November 5, 2020, 11:19pm UTC](https://forums.unrealengine.com/t/tsharedref-for-interface/474068 "2020-11-05T23:19:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bionic\_Ape](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bionic_ape/32/1090124_2.png) [@Bionic\_Ape](https://forums.unrealengine.com/u/Bionic_Ape)\
**Post date:** [November 5, 2020, 11:19pm UTC](https://forums.unrealengine.com/t/tsharedref-for-interface/474068/1 "2020-11-05T23:19:00Z")

</div>

I want to have a TMap of interfaces, but I want them to be garbage collected when nobody is referencing them.

If I use `TMap<int32,TWeakPtr<IMyType>>` it can be garbage collected, but TSharedRef can’t be an interface.

if I use `TMap<int32,TScriptInterface<IMyType>>` can’t be garbage collected.  
If I use `TMap<int32, IMyType*>` won’t compile.

Is there anyway to use TWeakPtr with Interfaces?

Cheers,
