resource-management-audit

Audit OpenGL resource cleanup and IDisposable patterns to prevent GPU leaks.

13|2|Updated Jul 17, 2023
One-click install
npx skills add https://github.com/kateusz/GameEngine --skill resource-management-audit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: resource-management-audit
Source: https://github.com/kateusz/GameEngine/tree/main/.claude/skills/resource-management-audit
Command: npx skills add https://github.com/kateusz/GameEngine --skill resource-management-audit

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill audits resource management to ensure proper cleanup of OpenGL resources, correct IDisposable implementation, and prevention of memory leaks. It focuses on critical engine-specific concerns like OpenGL context safety, factory ownership patterns, and GPU resource tracking, which are vital for stable and performant game execution.

Core Features & Use Cases

  • IDisposable Verification: Checks for correct IDisposable implementation, including _disposed flags, resource ID resets, and GC.SuppressFinalize.
  • OpenGL Context Safety: Enforces the rule that OpenGL calls must never occur in finalizers to prevent crashes.
  • Ownership Clarity: Distinguishes between factory-managed (shared) and component-owned resources to prevent premature disposal.
  • Memory Leak Detection: Identifies missing disposal paths for resources created in loops or without explicit cleanup.
  • Use Case: When investigating a GPU memory leak that occurs after repeatedly loading and unloading scenes, this Skill can audit Mesh and Texture classes to ensure their OpenGL IDs are correctly deleted and that shared resources are not prematurely disposed by individual components.

Quick Start

Audit the Texture class for proper IDisposable implementation, ensuring GL.DeleteTexture is called correctly and GC.SuppressFinalize is used.

Frequently Asked Questions about resource-management-audit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent memory leaks in OpenGL resource management?

Memory leaks in OpenGL occur when textures, buffers, shaders, or framebuffers aren't properly deleted. Implement correct IDisposable patterns with _disposed flags, call GL.Delete methods explicitly, and use GC.SuppressFinalize to prevent finalizer execution that could crash the OpenGL context.

Why should OpenGL calls never happen in finalizers?

OpenGL calls in finalizers are unsafe because finalizers run on arbitrary threads without guaranteed context binding, causing crashes or undefined behavior. Always perform resource cleanup in Dispose methods, not finalizers, to ensure thread-safe context access.

How do I audit IDisposable implementation for GPU resources?

Audit IDisposable implementation by verifying _disposed guard checks, confirming GL.Delete calls for each resource type, resetting resource IDs to zero, and calling GC.SuppressFinalize. Check factory-owned versus component-owned patterns to prevent premature disposal of shared resources.

What's the difference between factory-owned and component-owned resources in OpenGL?

Factory-owned resources are managed centrally and shared across components; components should not dispose them. Component-owned resources are created and managed by individual components with exclusive disposal responsibility. Mixing these patterns causes double-deletion or resource exhaustion.

How do I detect GPU resource exhaustion when loading and unloading scenes?

GPU resource exhaustion manifests as memory leaks or crashes during repeated scene loads. Audit Mesh and Texture classes to ensure OpenGL IDs are correctly deleted on disposal, verify no orphaned resources accumulate, and confirm shared factory resources aren't disposed by individual components.

Can I use this audit process with different OpenGL resource types?

Yes, the audit checklist applies to all OpenGL resource types: textures, buffers, shaders, and framebuffers. The core pattern—IDisposable implementation, GL.Delete calls, ownership clarity, and disposal guards—remains consistent across resource types.