Skip to content

Conversation

@ELDment
Copy link
Contributor

@ELDment ELDment commented Jan 20, 2026

        public override void Load(bool hotReload)
        {
            RegisterListener<Listeners.OnTick>(() =>
            {
                for (int j = 0; j < 32; j++)
                {
                    for (int i = 0; i < 64; i++)
                    {
                        var vector = new Vector(i, i, i);
                    }
                }
            });
        }

        [ConsoleCommand("css_tp")]
        public void OnTeleportCommand(CCSPlayerController? player, CommandInfo commandInfo)
        {
            var vector = new Vector(0, 0, 500);
            commandInfo.ReplyToCommand($"{vector} -> ({NativeAPI.VectorGetX(vector.Handle)}, {NativeAPI.VectorGetY(vector.Handle)}, {NativeAPI.VectorGetZ(vector.Handle)}) | {NativeAPI.VectorIsZero(vector.Handle)}");
            NativeAPI.VectorSetZ(vector.Handle, 1000);
            player!.PlayerPawn.Value!.Teleport(vector);
        }
image

Performs well on Windows with no noticeable memory leaks or CPU overhead increase
Backward compatibility tested with no issues


Maybe this is just a draft? i'm not sure, there might be a better way, idk
If it is good to go, please merge, lol

@ELDment ELDment requested a review from roflmuffin as a code owner January 20, 2026 17:43
@roflmuffin
Copy link
Owner

I think this concept seems sound to me, converting to handles only as required. I'll just run some tests on my end.

@ELDment ELDment changed the title refactor: Fix memory leaks refactor: Fix memory leak caused by allocating Vector, QAngle, etc. class objects Jan 27, 2026
@roflmuffin
Copy link
Owner

Happy to merge and release @ELDment?

@ELDment
Copy link
Contributor Author

ELDment commented Jan 27, 2026

Happy to merge and release @ELDment?

of course 🎉

@roflmuffin roflmuffin merged commit f06283a into roflmuffin:main Jan 27, 2026
6 checks passed
@KillStr3aK
Copy link
Contributor

its been a while for me, layout-wise it might be okay but wouldn't there be issues if the variable isn't allocated using memalloc?

@ELDment ELDment deleted the fix-leak branch January 29, 2026 05:03
@ELDment
Copy link
Contributor Author

ELDment commented Jan 29, 2026

its been a while for me, layout-wise it might be okay but wouldn't there be issues if the variable isn't allocated using memalloc?

imo, we don’t need memalloc here because we’re not creating an engine-owned C++ object that the engine will later free via its allocator, we’re just passing a pointer to a POD layout (3 contiguous floats) that native code reads/writes as Vector* and does not delete/free

in that case the allocator is irrelevant, AllocHGlobal is fine as long as the layout matches and the memory stays alive for the duration of the call

not sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants