oscerd opened a new pull request, #25853:
URL: https://github.com/apache/camel/pull/25853

   ## Issue
   [CAMEL-24529](https://issues.apache.org/jira/browse/CAMEL-24529)
   
   ## Problem
   Every `Zoo*Predictor` loads a `ZooModel` via `ModelZoo.loadModel(...)` in 
its constructor and holds it
   for the lifetime of the producer:
   
   ```java
   this.model = ModelZoo.loadModel(criteria);
   ```
   
   Nothing ever closed that model — `DJLProducer` had no `doStop()` and 
`AbstractPredictor` had no close
   hook. A `ZooModel` owns native memory and file handles (the loaded engine 
model), so on every route
   stop or redeploy the model was leaked. Long-running deployments that restart 
routes accumulate native
   memory until the process is killed.
   
   ## Fix
   - Add a `close()` lifecycle method to `AbstractPredictor`, a **no-op by 
default** so the custom
     predictors (which hold no long-lived model, looking one up per exchange) 
are unaffected.
   - Override `close()` to close the held model in the zoo predictors and their 
two base classes
     (`AbstractCvZooPredictor`, `AbstractNlpZooPredictor` cover the CV/NLP zoo 
predictors;
     `ZooQuestionAnswerPredictor`, `ZooAudioPredictor`, 
`ZooImageGenerationPredictor`,
     `ZooForecastingPredictor` hold their own model).
   - `DJLProducer.doStop()` now calls `predictor.close()`.
   
   ## Testing
   - New `DJLProducerTest` verifies that starting and stopping the producer 
(which invokes
     `doStop -> predictor.close()`) completes without error on the custom, 
model-less path.
   - The zoo predictors' `close()` overrides close the model behind an 
inspection-level guard
     (`if (model != null) model.close()`); loading a real zoo model to assert 
the native close requires
     network access and is out of scope for a unit test.
   - `mvn -Psourcecheck validate` green.
   
   _Claude Code on behalf of oscerd_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to