Skip to content

Fix MethodRpc GCHandle leak#104

Open
naxturnal wants to merge 1 commit into
NuclearPowered:masterfrom
naxturnal:fix/gchandle-leak
Open

Fix MethodRpc GCHandle leak#104
naxturnal wants to merge 1 commit into
NuclearPowered:masterfrom
naxturnal:fix/gchandle-leak

Conversation

@naxturnal

Copy link
Copy Markdown

Problem

GCHandle.Alloc(this) pins the MethodRpc instance forever, causing a memory leak over time.

Solution

Replaced with a static Dictionary<uint, MethodRpc> cache. Each RPC gets a unique sender ID stored as an instance field. Added cleanup methods:

  • Unregister() - removes individual RPC from cache
  • UnregisterPlugin(plugin) - cleans up all RPCs for a plugin on unload
  • CleanupDeadReferences() - full cache clear

Also added a debug assertion to catch sender ID collisions.

Benefits

  • Fixes the memory leak
  • Simpler IL generation

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.

1 participant