# \[New Wiki\] Memory Management, Count References to Any Object, and Know Who is Referring!

**URL:** <https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 26, 2016, 7:55pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401 "2016-03-26T19:55:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 26, 2016, 7:55pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/1 "2016-03-26T19:55:59Z")

</div>

Dear Community,

I’ve just released a new wiki that shows you how you can count references to any AActor/UObject yourself!

You can also get an Object list of exactly who is referring to your UObject!

The code is quite simple, and I am using built-in runtime engine tools.

**Garbage Collection ~ Count References to Any Object**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Enjoy!

Rama

Sample output:

```auto

TArray<UObject*> Referencers;
 
GetObjReferenceCount(this,&Referencers);
 
for(UObject* Each : Referencers)
{
	if(Each)
	{
		UE_LOG(YourLog,Warning,TEXT("%s"), *Each->GetName());
	}
}

```

 ![ObjRefCount.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/6/e6e94af5897fa9f378f6093cfdba3c88149a32b8.jpeg)

---

<div class="post-metadata">

**Author:** ![MPalacios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MPalacios](https://forums.unrealengine.com/u/MPalacios)\
**Post date:** [March 27, 2016, 5:39pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/2 "2016-03-27T17:39:04Z")

</div>

You are the best!

---

<div class="post-metadata">

**Author:** ![Grogger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grogger](https://forums.unrealengine.com/u/Grogger)\
**Post date:** [March 28, 2016, 6:54pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/3 "2016-03-28T18:54:06Z")

</div>

Thanks Rama, this should come in handy!

I noticed the return value in your example should probably be “ReferredToObjects.Num()” instead of the array pointer.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 28, 2016, 9:43pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/4 "2016-03-28T21:43:04Z")

</div>

> [@Grogger;501449](#):
>
> Thanks Rama, this should come in handy!
> 
> I noticed the return value in your example should probably be “ReferredToObjects.Num()” instead of the array pointer.

I changed the name in the code at one point and must have not added that, but it is correct now on the wiki, so all is well 🙂

I hope you are having fun today!

> [@MPalacios;500912](#):
>
> You are the best!

Hee hee!

❤

Rama

---

<div class="post-metadata">

**Author:** ![Andy\_rst](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andy\_rst](https://forums.unrealengine.com/u/Andy_rst)\
**Post date:** [March 28, 2016, 9:55pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/5 "2016-03-28T21:55:16Z")

</div>

Thanks Rama! Great stuff!

---

<div class="post-metadata">

**Author:** ![msvcrt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@msvcrt](https://forums.unrealengine.com/u/msvcrt)\
**Post date:** [March 29, 2016, 4:20am UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/6 "2016-03-29T04:20:37Z")

</div>

Thanks again, Rama! This is very useful information.

---

<div class="post-metadata">

**Author:** ![xCANAdan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@xCANAdan](https://forums.unrealengine.com/u/xCANAdan)\
**Post date:** [May 26, 2023, 5:35am UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/7 "2023-05-26T05:35:55Z")

</div>

hey, would it be possible to get an update of this code, with the wiki being shut down and all that?  
im getting some really odd issues with GC and something like this would be extremely helpful for telling me what references arnt being resolved.

---

<div class="post-metadata">

**Author:** ![kato4000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kato4000](https://forums.unrealengine.com/u/kato4000)\
**Post date:** [October 31, 2023, 1:54pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/8 "2023-10-31T13:54:04Z")

</div>

This seems to be the content of the original link  
[Garbage Collection ~ Count References To Any Object | Unreal Engine Community Wiki (unrealcommunity.wiki)](https://unrealcommunity.wiki/garbage-collection-~-count-references-to-any-object-2afrgp8l)

---

<div class="post-metadata">

**Author:** ![Rjmcf90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rjmcf90](https://forums.unrealengine.com/u/Rjmcf90)\
**Post date:** [May 15, 2024, 4:48pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/9 "2024-05-15T16:48:41Z")

</div>

The link above seems to be about counting the objects that my object references. I needed a way to count all the objects that reference my object instead. This seems to be the first result on Google for that sort of question, so here’s what worked for me in UE 5.3:

```auto
TArray<UObject*> GetReferencesToLiveObject(UObject* Obj)
{
    if(!Obj || !Obj->IsValidLowLevelFast())
        return {};

    FReferencerInformationList List;
    IsReferenced(Obj, RF_AllFlags, EInternalObjectFlags::AllFlags, true, &List);
    
    TArray<UObject*> Referencers;
    for (const auto& Reference : List.ExternalReferences)
        Referencers.Add(Reference.Referencer);

    return Referencers;
}

```

I personally chose to use `AllFlags` for those parameters because I didn’t want to miss anything, but potentially some of the results could be CDOs, or partway through destruction, or otherwise unhelpful. There might be nicer values that would exclude those.

Also, that `Reference` variable there has some other nice information in it that I didn’t need but might be useful to you:

- The number of times the `Reference.Referencer` object actually references `Obj`
- The properties of the `Reference.Referencer` object that are actually doing the referencing, stored in `Reference.ReferencingProperties`.

---

<div class="post-metadata">

**Author:** ![ckf104](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ckf104](https://forums.unrealengine.com/u/ckf104)\
**Post date:** [February 9, 2025, 2:41pm UTC](https://forums.unrealengine.com/t/new-wiki-memory-management-count-references-to-any-object-and-know-who-is-referring/59401/10 "2025-02-09T14:41:16Z")

</div>

`IsReferenced` function will set `UE::GC::GUnreachableObjectFlag` for unreachable objects, which will mess up ordinary GC flow. You can see that `VerifyObjectFlags` function will be called when GC starts to check that each object should not contain `UE::GC::GUnreachableObjectFlag` and `UE::GC::GMaybeUnreachableObjectFlag`.

After searching source code, I find that `IsReferenced` is only used by unreal editor, and there is no automatic GC before you click PIE. So I guess that unreal editor may do something like garbage purge after using `IsReferenced` function to keep things work.

For a safer choice, I would suggest to use `FReferencerFinder::GetAllReferencers` to find all objects that reference given objects, even though it don’t provide detailed reference counting and reference property.
