Answered by:
Memory leak in IFaceModel::CalculateVerticesForAlignment

Question
-
I am using the HD Face Reconstruction in Kinect.Face. The following code is run every frame to create the face model:
IHighDefinitionFaceFrame* pHighDefinitionFaceFrame; hr = _pHighDefinitionFaceFrameReader->AcquireLatestFrame(&pHighDefinitionFaceFrame); if (SUCCEEDED(hr)) { INT64 nTime = 0; hr = pHighDefinitionFaceFrame->get_RelativeTime(&nTime); if (SUCCEEDED(hr)) { hr = pHighDefinitionFaceFrame->GetAndRefreshFaceAlignmentResult(_pFaceAlignment); } if (SUCCEEDED(hr)) { hr = pHighDefinitionFaceFrame->get_FaceModel(&_pFaceModel); } if (SUCCEEDED(hr)) { hr = _pFaceModel->CalculateVerticesForAlignment(_pFaceAlignment, _vertices.size(), &_vertices[0]); }
_pFaceModel->Release(); pHighDefinitionFaceFrame->Release(); }
_vertices in this case is declared once in the constructor like this:
vector<CameraSpacePoint> _vertices; UINT32 vertexCount; GetFaceModelVertexCount(&vertexCount); _vertices.resize(vertexCount);
The line
_pFaceModel->CalculateVerticesForAlignment(_pFaceAlignment, _vertices.size(), &_vertices[0]);
seems to leak memory. As soon as this line is commented out, no memory is leaked. Can anyone tell me what I'm doing wrong?
Thank you very much.
- Edited by Dominik Giger Thursday, September 4, 2014 3:35 PM formatting of the code improved
Thursday, September 4, 2014 3:34 PM
Answers
-
Hi Kinect team
I have confirmed that the problem of memory leak have been fixed in SDK 1409.
Thank you for the quickly fix.- Marked as answer by Carmine Si - MSFTMicrosoft employee Thursday, September 18, 2014 6:31 PM
Wednesday, September 17, 2014 3:44 PM
All replies
-
Anyone have any idea why this is happening? It does work when using the Win8.1 API.Tuesday, September 9, 2014 8:24 AM
-
Hi Dominik, and Kinect team
I think cause of memory leak is included in the IFaceModel::CalculateVerticesForAlignment() too.
My HDFace Program is here.
Kinect team, Are you recognize this problem?
Best Regards,
Thank you.Thursday, September 11, 2014 6:06 PM -
This has been addressed in a newer build. When we have another update to the SDK, check that version against your sample to ensure this is resolved.
Why are you re-creating the face model object every frame? You should only be creating one per body id, until you no longer need it.
Carmine Sirignano - MSFT
- Proposed as answer by Carmine Si - MSFTMicrosoft employee Friday, September 12, 2014 12:20 AM
Friday, September 12, 2014 12:20 AM -
Thanks everyone. I will wait for the new version to be released.
Btw. Do you know when the new version will be released? Or is it possible to access your dev-builds?
- Edited by Dominik Giger Friday, September 12, 2014 8:28 AM
Friday, September 12, 2014 8:22 AM -
Thats awesome!
I'm looking forward to the release of the next SDK.
When is it scheduled to be released?
Carmine, Thank you for your advice.
I corrected the source code of HDFace.
Thanks.
Friday, September 12, 2014 1:42 PM -
Hi Kinect team
I have confirmed that the problem of memory leak have been fixed in SDK 1409.
Thank you for the quickly fix.- Marked as answer by Carmine Si - MSFTMicrosoft employee Thursday, September 18, 2014 6:31 PM
Wednesday, September 17, 2014 3:44 PM -
Thanks everyone!Thursday, September 18, 2014 2:19 PM
-
I posted a similar problem here:
So it looks like the right way to do is to build the model once for each body and just update vertices? Cool. But how do I release whatever GetFaceModelTriangles is making? Releasing the IFaceModel stops any memory leak from IFaceModel::CalculateVerticesForAlignment for me, but GetFaceModelTriangles is a free function.
EDIT: I followed the advice to build the models once and then just update the vertices, but now I'm getting the memory leak the OP is talking about. I'm on Windows 8, not 8.1.
- Edited by Stephen Schieberl Wednesday, October 15, 2014 10:47 PM
Wednesday, October 15, 2014 10:18 PM -
GetFaceModelTriangles doesn't create any memory. It does a memcopy to the buffer you are passing in.
Carmine Sirignano - MSFT
Thursday, October 16, 2014 4:37 PM -
I overhauled my code a bit to create everything only once -- model, alignment, model builder, source, and reader -- with a cleanup routine at the end. No more memory leak. :)Friday, October 17, 2014 6:30 PM