My C++ code is written in Embarcadero 10.3.1. I am facing lot of memory leaks and resource leaks. I am unable to identify the leaks.
When I use CodeGaurd, the application freezes, so I'm unable to get any conclusions.
My application is a background job which continuously processes files and generates labels. It works fine for a couple of hours and generates around 3000 labels, and then goes to a hung/non-responsive state.
Can anyone suggest any solution?
Memory leaks can be difficult to track down. In your case I suspect that you are using a label printer with it's own library or driver and leaks could be anywhere.
Firstly you should try and understand what memory management models exist in the application. With C++ Builder code generally you will be responsible for allocating and freeing memory. So every object you create with
newshould have a correspondingdelete- make sure you understand what part of the code is responsible for freeing the object. (In 10.3.1 C++ Builder does support C++auto_ptrbut you may not be using this, and you can't guarantee that any library code you have linked in will honour theauto_ptrsemantics).If you are passing information into code that's using another memory management model (so using a COM Object is a good example) then make sure you understand the implications for memory management. If you pass it a pointer is it expecting to free it or is it expecting you to free it - and if it's you how do you know when it has finished with it.
Try running a smaller run and seeing if with a smaller run you can use CodeGuard and pick up anything it suggests.
If your system is in production you will want to keep it running. One option would be to run it as a Windows Scheduled Task. It will process a set number of files and exit. The O/S will free up resources it had in use (but not any that are being leaked at the system level, perhaps by a buggy driver). That may allow you to keep it running all day while you continue to find any leaks.
Good Luck!