hollance / Forge

A neural network toolkit for Metal
MIT License
1.27k stars 172 forks source link

A issues about memory leak #21

Closed gxl2024595 closed 6 years ago

gxl2024595 commented 6 years ago

i add a viewcontroller which as the first vc in MobileNetsDemo.Then present the cameracontroller in demo ,and then dismiss the cameracontroller .But i find that when i do this ,there is about 10M memory is not released.And everytime i present the cameracontroller ,there is more 10M in memory which is not released. i guess the issues is everytime createNeuralNetwork the memory will in increase,but i cannot solve the problem.How could i solve this problem??

hollance commented 6 years ago

You can use Instruments with the Allocations instrument to find out exactly where that extra 10MB comes from.

gxl2024595 commented 6 years ago

I had use Instruments to find out where that 10MB ,but i finally cannot find it .I had some screenshots.

01455bde-944c-4b66-8c8d-a800c55aff6a
gxl2024595 commented 6 years ago
a832ad3c-37f4-43be-8df1-c5f83736d606
gxl2024595 commented 6 years ago
374227cf-cbf9-476b-bcf4-0859f1a87173
gxl2024595 commented 6 years ago

when call this function ,the memory will increase,and when i dismiss the cameracontroller ,the extra 10MB would not be released

7818a0b0-6182-463c-8adb-8d8f88a1a501

Could you try to add a viewcontroller in your demo(MobileNets) ,and you can present the cameratroller and dismiss the cameratroller for sereval times.You will find the same issues.Please help me Great God^^

hollance commented 6 years ago

It's definitely not a good idea to create the neural network every time. Just create it once and keep re-using it.

gxl2024595 commented 6 years ago

But,if i want to swich the training model ,i have to create the neural network again.Is there any way to swich the training model without creating the neural network again?

hollance commented 6 years ago

At this point, no. There is no way to change the weights after you've created the model. So in that case you do have to create the neural network again.

gxl2024595 commented 6 years ago

Ok, i get it.Thanks.

hollance commented 6 years ago

@gxl2024595 I fixed the memory leak. Give it a try and see if it works for you.

gxl2024595 commented 6 years ago

Thank you,the memory leak is fixed.Thank you for your help!!