[Tech debt] SonarQube S1215: remove GC.Collect() calls (8 backend) #246

Closed
opened 2026-06-19 18:44:52 +00:00 by spikerj · 1 comment
Owner

Surfaced by SonarQube (api.spikersoft.com), rule csharpsquid:S1215, severity CRITICAL (MAINTAINABILITY). Manual GC.Collect() forces full collections that usually hurt throughput/latency and mask the real issue (e.g. large allocations, undisposed resources).

Locations

  • SpikerSoft.Business.Ai.Workers/Services/QuizGenerationService.cs:144, 344, 731, 733
  • SpikerSoft.EventHandlers.Embeddings/Services/EmbeddingGenerationService.cs:157, 175, 249, 251

Fix

Remove the calls; if memory pressure is real, address allocations directly (stream/chunk, dispose, pool buffers) rather than forcing GC.

Rule: https://rules.sonarsource.com/csharp/RSPEC-1215/

Surfaced by SonarQube (`api.spikersoft.com`), rule `csharpsquid:S1215`, severity CRITICAL (MAINTAINABILITY). Manual `GC.Collect()` forces full collections that usually hurt throughput/latency and mask the real issue (e.g. large allocations, undisposed resources). ## Locations - `SpikerSoft.Business.Ai.Workers/Services/QuizGenerationService.cs:144, 344, 731, 733` - `SpikerSoft.EventHandlers.Embeddings/Services/EmbeddingGenerationService.cs:157, 175, 249, 251` ## Fix Remove the calls; if memory pressure is real, address allocations directly (stream/chunk, dispose, pool buffers) rather than forcing GC. _Rule: https://rules.sonarsource.com/csharp/RSPEC-1215/_
spikerj added the sonarqube label 2026-06-19 18:44:52 +00:00
Author
Owner

Resolved in spikersoft-backend PR #12 (merged to master). Note the approach differs from the ticket's "remove": the GC.Collect calls run only on LLama model-unload paths (QuizGenerationService, EmbeddingGenerationService) to promptly reclaim native/GPU memory the managed GC can't see — removing them risks OOM on the next model load. So S1215 is suppressed file-wide with a documented justification rather than deleting the calls. Closing.

Resolved in spikersoft-backend PR #12 (merged to `master`). Note the approach differs from the ticket's "remove": the `GC.Collect` calls run only on LLama model-unload paths (`QuizGenerationService`, `EmbeddingGenerationService`) to promptly reclaim native/GPU memory the managed GC can't see — removing them risks OOM on the next model load. So `S1215` is suppressed file-wide with a documented justification rather than deleting the calls. Closing.
Sign in to join this conversation.