/** * GPU Resource Tracker for three-cad-viewer. * * Tracks Three.js GPU resources (geometries, materials, textures) to detect memory leaks * or inspect current allocations. By default, only maintains counts. Enable debug mode * for detailed creation info. * * @example * // Check resource counts * import { gpuTracker } from "three-cad-viewer"; * console.log(gpuTracker.summary); * // { geometry: 5, material: 10, texture: 1, total: 16 } * * @example * // Debug mode - see detailed allocation info * gpuTracker.enableDebug(); * // ... create viewer and render objects ... * gpuTracker.details(); // Shows what's currently allocated * // ... dispose viewer ... * gpuTracker.details(); // After dispose, shows any leaks */ /** Resource types tracked by the GPU tracker */ export type ResourceType = "geometry" | "material" | "texture"; /** Information about a tracked resource (debug mode only) */ export interface TrackedResource { /** Type of GPU resource */ type: ResourceType; /** Human-readable label for identification */ label: string; /** Stack trace at creation time (truncated) */ stack: string; /** Timestamp of creation (performance.now()) */ timestamp: number; } /** Summary of current resource counts */ export interface ResourceSummary { geometry: number; material: number; texture: number; total: number; } /** * GPU Resource Tracker. * * Tracks creation and disposal of Three.js GPU resources to help detect memory leaks. * Access via `window.tcv_gpu` in browser console for debugging. */ export declare const gpuTracker: { /** * Enable debug mode to capture creation info (stack traces, labels). * Call before creating any viewer resources for full tracking. * * Performance impact: Captures stack trace on every resource creation. * Only enable when debugging leaks. */ enableDebug(): void; /** * Disable debug mode and clear tracked objects. */ disableDebug(): void; /** * Check if debug mode is enabled. */ readonly isDebugEnabled: boolean; /** * Track a GPU resource creation. * * @param type - Resource type (geometry, material, texture) * @param obj - The Three.js object being tracked * @param label - Optional descriptive label (e.g., "front face material for /Assembly/Part1") */ track(type: ResourceType, obj: object, label?: string): void; /** * Untrack a GPU resource after disposal. * * @param type - Resource type (required in non-debug mode) * @param obj - The Three.js object being untracked (optional in non-debug mode) */ untrack(type: ResourceType, obj?: object): void; /** * Get current resource counts. */ readonly summary: ResourceSummary; /** * Get all tracked resources (debug mode only). * * @returns Array of currently tracked resources */ getResources(): TrackedResource[]; /** * Get tracked resources grouped by type. */ getResourcesByType(): Record; /** * Log details of currently tracked resources. * Useful for inspecting allocations or detecting leaks after disposal. * Always outputs to console regardless of logger level. */ details(): void; /** * Reset all counters and tracked objects. * Useful for testing or starting fresh. */ reset(): void; /** * Assert that all resources have been disposed. * Useful in tests. * * @throws Error if any resources remain */ assertEmpty(): void; /** * Track a geometry and return it (for chaining). */ trackGeometry(geometry: T, label?: string): T; /** * Track a material and return it (for chaining). */ trackMaterial(material: T, label?: string): T; /** * Track a texture and return it (for chaining). */ trackTexture(texture: T, label?: string): T; };