Jump to content

How does one handle resource cleanup in Unreal Script land?


serratemplar

Recommended Posts

Hi everybody! I'm new here and new to UE3, and modding in general. Thanks in advance for your time. :smile:

For a class I need access to (ones that I can't override and need info from) I've taken to spawning them like this:

CharacterGenerator = `XCOMGAME.Spawn( class 'XGCharacterGenerator' );

At first, I was doing this in each function in my own Listener class, and setting up locally scoped vars assuming they'd be garbage collected upon function return.

local XGCharacterGenerator CharacterGenerator;

I got worried this might result in a memory leak as I wasn't 100% certain how UE3 (or any version of UDK for that matter) handled this stuff; maybe I was actually safe, but upon reading the doc page for Spawn, I found myself more convinced I should do a manual cleanup, by making one class-wide scoped var, removing all the locals, then putting Destroy calls in my Listener class's OnRemoved function, thus:

event OnRemoved(UIScreen Screen)
{
	CharacterGenerator.Destroy();

	RandomFirstnameButton.Destroy();
	RandomNicknameButton.Destroy();
	RandomLastnameButton.Destroy();
	RandomCountryButton.Destroy();
}

Is this correct? Should I in fact be viewing Spawn the same way I view C++'s new operator? Or is that approach confusing me?

 

EDITS. Clarifications.

Edited by serratemplar
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...