# Will raw pointer, new keyword, in UFunction body, cause memory leak?

**URL:** <https://forums.unrealengine.com/t/will-raw-pointer-new-keyword-in-ufunction-body-cause-memory-leak/455400>\
**Category:** Rendering\
**Tags:** reflection, ufunction, unreal-engine, memory, pointer, question\
**Created:** [September 15, 2019, 10:11pm UTC](https://forums.unrealengine.com/t/will-raw-pointer-new-keyword-in-ufunction-body-cause-memory-leak/455400 "2019-09-15T22:11:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_91b492f1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_91b492f1](https://forums.unrealengine.com/u/anonymous_user_91b492f1)\
**Post date:** [September 15, 2019, 10:11pm UTC](https://forums.unrealengine.com/t/will-raw-pointer-new-keyword-in-ufunction-body-cause-memory-leak/455400/1 "2019-09-15T22:11:23Z")

</div>

I followed this tutorial: [A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums](https://wiki.unrealengine.com/Creating_%26_Linking_Static_Libraries_And_Make_Your_Own_Blueprint_Node_With_VS_2017_%26_UE4) to create a static library.

It is a great tutorial. However I noticed when implementing a UFunction, they create a c++ object using the new keyword, allocating memory, than return from the function without deleting the memory.

so my question is, since this is happening inside of a UFunction, is the memory managed? Or is this a memory leak?

```
.h
UCLASS()
class UE4MAGIC_API UYJLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
		UFUNCTION(BlueprintCallable, meta = (DisplayName = "Adds floats", Keywords = "Float Add"), Category = YJLibrary)
		static float AddFloats(float A, float B);
	
};

.cpp
#include "YJLibrary.h"
#include "YJMagic.h"

float UYJLibrary::AddFloats(float A, float B)
{
	YJMagic::YJMagic *PointerToYJMagic;
	
	PointerToYJMagic = new YJMagic::YJMagic();

	return PointerToYJMagic->Add(A, B);
}

```
