Solved memory leak at matrix