I’ve followed the tutorial about http requests at the unreal website
but every time i run my project the memory keeps increasing i’ve already added some of my code. Everything works exept for the memory that keeps increasing every time i run the project. Do i need to dealloc the arrays and stuff i create in my receive method or does the automatic garbage collection do that? I remove the Actor after the parsing of my json is done. Sorry i’m new to UE4
#include "databaseRequest.h"
#include "JsonUtilities.h"
#include "DrawDebugHelpers.h"
#include "MyTestStreet.h"
#include "Engine/World.h"
// Sets default values
AdatabaseRequest::AdatabaseRequest(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
//When the object is constructed, Get the HTTP module
Http = &FHttpModule::Get();
}
// Called when the game starts or when spawned
void AdatabaseRequest::BeginPlay()
{
MyHttpCall();
Super::BeginPlay();
}
/*Http call*/
void AdatabaseRequest::MyHttpCall()
{
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &AdatabaseRequest::OnResponseReceived);
//This is the url on which to process the request
Request->SetURL("MyURL");
Request->SetVerb("GET");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->ProcessRequest();
}
void AdatabaseRequest::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
//Create a pointer to hold the json serialized data
TSharedPtr<FJsonObject> JsonObject;
//Create a reader pointer to read the json data
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
FString json = FString(Response->GetContentAsString());
//
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
UE_LOG(LogTemp, Warning, TEXT("IN IF"));
TArray<TSharedPtr<FJsonValue>> streetArray = JsonObject->GetArrayField("streets");
TSharedPtr<FJsonObject> minValues = JsonObject->GetObjectField("minValues");
TSharedPtr<FJsonObject> maxValues = JsonObject->GetObjectField("maxValues");
int32 minLat = FCString::Atoi(*minValues->GetStringField("minLat"));
int32 minLon = FCString::Atoi(*minValues->GetStringField("minLon"));
int32 maxLat = FCString::Atoi(*maxValues->GetStringField("maxLat"));
int32 maxLon = FCString::Atoi(*maxValues->GetStringField("maxLon"));
UE_LOG(LogTemp, Warning, TEXT("minLat: %d"), minLat);
UE_LOG(LogTemp, Warning, TEXT("minLon: %d"), minLon);
UE_LOG(LogTemp, Warning, TEXT("maxLat: %d"), maxLat);
UE_LOG(LogTemp, Warning, TEXT("maxLon: %d"), maxLon);
TArray<int32> lat;
TArray<int32> lon;
for (int i = 0; i < streetArray.Num(); i++) {
TSharedPtr<FJsonObject> street = streetArray[i]->AsObject();
int32 streetId = FCString::Atoi(*street->GetStringField("osm_id"));
FString highway = street->GetStringField("highway");
TArray<TSharedPtr<FJsonValue>> nodesArray = street->GetArrayField("nodes");
for (int j = 0; j < nodesArray.Num(); j++) {
TSharedPtr<FJsonObject> node = nodesArray[j]->AsObject();
int64 nodeId = FCString::Atoi64(*node->GetStringField("id"));
int32 nodeLat = FCString::Atoi(*node->GetStringField("lat"));
int32 nodeLon = FCString::Atoi(*node->GetStringField("lon"));
lat.Add((nodeLat - minLat) / 2500);
lon.Add((nodeLon - minLon) / 2500);
}
}
UE_LOG(LogTemp, Warning, TEXT("Array Size lat: %d"), lat.Num());
UE_LOG(LogTemp, Warning, TEXT("Array Size lon: %d"), lon.Num());
if (!this) return;
if (!this->IsValidLowLevel()) return;
this->Destroy();
this->ConditionalBeginDestroy();
}
else {
UE_LOG(LogTemp, Warning, TEXT("IN ELSE"));
}
}