agentleFS
d-o-hubd-o-hub/github-template-ai-agents/.agents/skills/lifecycle-management/SKILL.md

lifecycle-management

Skill2 starsChanged 11 days agoMITView on GitHub

Manage application lifecycle, error handling, and resource cleanup to prevent memory leaks and ensure stability. Use this skill when handling startup/shutdown sequences, managing resource pools, implementing error boundaries, preventing memory leaks, or ensuring graceful degradation — even if they just say "clean up resources" or "fix the memory leak". Not for security-code-auditor.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Call lifecycle.cleanupRoute() before navigating to cancel in-flight fetch requests via a global AbortController.

    line 41
  2. Very specific:

    Use AbortController signal for all addEventListener calls where possible to automate cleanup.

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Lifecycle Management

Generic patterns for managing application lifecycle, specifically for web applications to prevent memory leaks and handle global errors.

When to Use

  • User asks to handle startup/shutdown sequences or manage resource pools
  • Need to implement error boundaries or prevent memory leaks
  • Even if they just say "clean up resources" or "fix the memory leak"

Patterns

Global Error Handler

initGlobalErrorHandling() MUST be called to catch uncaught exceptions and unhandled rejections.

function initGlobalErrorHandling() {
  window.addEventListener('error', (event) => {
    console.error('Uncaught exception:', event.error);
    // Add telemetry/reporting here
  });

  window.addEventListener('unhandledrejection', (event) => {
    console.error('Unhandled rejection:', event.reason);
    // Add telemetry/reporting here
  });
}

Route Cleanup

Call lifecycle.cleanupRoute() before navigating to cancel in-flight fetch requests via a global AbortController.

const lifecycle = {
  controller: new AbortController(),
  cleanupRoute() {
    this.controller.abort();
    this.controller = new AbortController();
  }
};

Event Listeners

Use AbortController signal for all addEventListener calls where possible to automate cleanup.

const controller = new AbortController();
const { signal } = controller;

// handleResize must be defined in your component or module
window.addEventListener('resize', handleResize, { signal });

// Later, to remove all listeners associated with this controller:
controller.abort();

See Also

  • security-code-auditor — Security audits
  • pwa-offline-sync — Service workers and caching

Rationalizations

RationalizationReality
"It's just a small app, no leaks."Memory leaks accumulate over time and affect performance and stability even in small apps.
"I'll remove listeners manually."Manual removal is error-prone and often forgotten. AbortController is a cleaner, more robust pattern.

Red Flags

  • addEventListener used without a corresponding removeEventListener or signal.
  • No global error handling implementation.
  • In-flight requests not cancelled during navigation or component unmounting.

Voice & Context

  • Default: professional + blog
  • Reference: voice-profiles skill for definitions and auto-detection.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.