Skip to content

Native call to 'delete' doesn't free memory #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
karambaso opened this issue Mar 23, 2025 · 2 comments
Open

Native call to 'delete' doesn't free memory #102

karambaso opened this issue Mar 23, 2025 · 2 comments

Comments

@karambaso
Copy link

If create a new LlamaModel and then close it then nothing is freed by native code.

To reproduce the issue it is enough to run this code:

public static void testCloseLoop(String modelPath)
{
	ModelParameters modelParameters=new ModelParameters();
	modelParameters.setModel(modelPath).setThreads(4).setKeep(-1).setCtxSize(1024).setGpuLayers(0);
	for (int i=0;i<10;i++)
	{
	    LlamaModel lamaModel = new LlamaModel(modelParameters);
	    lamaModel.close();
	    try { synchronized (lamaModel) { lamaModel.wait(100); } }
	    catch (InterruptedException e) { System.out.println(e); }
	}
}

The number of cycles depends on memory size on your computer. With GPU an exception is thrown after memory limit is exceeded while on CPU after memory limit is reached the swap space is employed and things become very ugly.

Introduction of delay doesn't help, despite of hope of waiting for some time, required for OS to free the memory, could help.

@vaiju1981
Copy link
Contributor

vaiju1981 commented Mar 25, 2025

This should be fixed in the new version to be released soon. PR ( #100 )

@karambaso
Copy link
Author

Thanks, quick response, ready to improve!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants