Will It Vibe logoWill It Vibe?
GO-014Low severity-4 points

time.After called inside a for loop

Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.

What it detects

time.After allocates a new timer on every call and that timer is not released until it fires, so calling it once per loop iteration builds up timers that outlive the iteration that created them. Prefer a single reusable time.Timer/time.Ticker created outside the loop.

Why it matters

time.After creates a brand-new timer every time it is called and that timer is not eligible for cleanup until it either fires or the process ends; calling it once per loop iteration (commonly inside a select inside a for) means every iteration that does not hit the timer case still leaves a live timer object behind, and over a long-running loop this accumulates into a real, gradually worsening memory and CPU cost.

How to fix it

Create the timer once, outside the loop, with time.NewTimer or time.NewTicker, and reuse it across iterations (resetting it with Reset if it is a one-shot Timer you need to rearm). Remember to call Stop() on a Timer you create this way once it is no longer needed, to release it promptly instead of waiting for it to fire.

The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing

Does your repo trip this check?

Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.

Scan your repo

Related Code Quality & Syntax checks