IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C++ Discussion :

Comportement desallocation de mémoire


Sujet :

C++

  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    265
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 265
    Points : 352
    Points
    352
    Par défaut Comportement desallocation de mémoire
    Bonjour,
    je constate un comportement de mon code que je n'arrive pas a expliquer. ^^
    je travaille avec VS2013 sur windows 7.

    Problème : mon code a une grosse fuite mémoire bien sale ^^
    je monitore donc la mémoire de mon process pour essayer d'identifier la source du problème.
    voici mon main :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
     
    for (int i = 0; i < 1000; i++)
    		{
    			cout << "Debut Process image " << i << endl;
    			GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			SIZE_T virtualMemUsedByPRocess_before_constructor = pmc.PagefileUsage;
     
    			WorkerBunny Worker(&Model, &params, source.c_str());
     
    			GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			SIZE_T virtualMemUsedByPRocess_after_constructor = pmc.PagefileUsage;
    			long int diff = virtualMemUsedByPRocess_after_constructor - virtualMemUsedByPRocess_before_constructor;
    			double ko = diff / 1024;
    			cout << ko << "     Ko alloué par le constructeur" << endl;
     
    			Worker.Matching();
     
    			GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			SIZE_T virtualMemUsedByPRocess_after_matching = pmc.PagefileUsage;
    			long int diff2 = virtualMemUsedByPRocess_after_matching - virtualMemUsedByPRocess_after_constructor;
    			double ko2 = diff2 / 1024;
    			cout << ko2 << "     Ko alloué par le Matching" << endl;
     
    			Worker.EstimateTransformation();
     
    			GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			SIZE_T virtualMemUsedByPRocess_after_EstimateTransformation = pmc.PagefileUsage;
    			long int diff3 = virtualMemUsedByPRocess_after_EstimateTransformation - virtualMemUsedByPRocess_after_matching;
    			double ko3 = diff3 / 1024;
    			cout << ko3 << "     Ko alloué par le EstimateTransformation" << endl;
     
    			Worker.ReleaseMemory();
     
    			GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			SIZE_T virtualMemUsedByPRocess_afterrelease = pmc.PagefileUsage;
    			long int diff4 = virtualMemUsedByPRocess_after_EstimateTransformation - virtualMemUsedByPRocess_afterrelease;
    			double ko4 = diff4 / 1024;
    			cout << ko4 << "     Ko desalloué par le ReleaseMemory" << endl;
    			long int diff5 = virtualMemUsedByPRocess_afterrelease - virtualMemUsedByPRocess_before_constructor;
    			double ko5 = diff5 / 1024;
    			cout << ko5 << "     ko Memoire non désaloué" << endl;
     
    			string Result = Worker.GetResult();
     
    			cout << Result << endl << endl;
    		}
    lorsque j'éxécute ce code, je constate des fuites mémoire provenant du constructeur et de la fonction Matching.

    lorsque je mets en commentaire la méthode EstimateTransformation je n'ai plus de problème de mémoire dans les 2 fonction précédente...

    je suis perdu ^^
    j'ai testé mes fonctions une par une indépendamment des autres et dans ces cas je n'ai pas de fuite
    avec la dernière (EstimateTransformation) par contre ça fuit mais le monitoring annonce que la fuite ne viens pas d'elle....


    merci pour votre aide

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    780
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2006
    Messages : 780
    Points : 1 176
    Points
    1 176
    Par défaut
    Il faudrait surtout voir le code où il y a les new et les delete...

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    265
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 265
    Points : 352
    Points
    352
    Par défaut
    le code s'appuie sur OpenCV 2.4.13

    prototype de la classe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    class DllExport WorkerBunny{
     
    private :
    	bool initnonfree;
    	bool initfeatures2d;
    	RAD_Params *params;
    	RAD_Image I;
    	RAD_Model *Model;
    	bool GPU;
    	float descriptor_time;
    	float Matching_time;
    	float Transformation_time;
    	float ProcessTime;
    	vector<MatchingPointStruct> vect_Matched_Model_keypoints;
    	EstimationTransformationStruct TransformationStruct;
    	HANDLE ghMutex;
     
    public :
    	// Methode
    	//vector<MatchingPointStruct> WorkerBunny::Matching();
    	void WorkerBunny::Matching();
    	vector<int>  WorkerBunny::RemoveWeakMatches(Mat distMat, const char* method, bool GPU_Mode);
    	//EstimationTransformationStruct  WorkerBunny::EstimateTransformation(vector<MatchingPointStruct> vect_Matched_Model_keypoints);
    	void  WorkerBunny::EstimateTransformation();
     
     
    	WorkerBunny::WorkerBunny( RAD_Model* Loaded_Model,  RAD_Params *Loaded_params, const char * source);
    //	int WorkerBunny::ProcessMatching();
    	string WorkerBunny::GetResult();
    	float WorkerBunny::GetFeaturesExtractionTime();	
    	float WorkerBunny::GetFeaturesMatchingTime();	
    	float WorkerBunny::GetTransformationTime();
    	float WorkerBunny::GetGlobalProcessTime();
    	void WorkerBunny::TerminateProcess();
    	void WorkerBunny::ReleaseMemory();
     
    };
    constructeur de la classe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
     
    WorkerBunny::WorkerBunny(RAD_Model* Loaded_Model, RAD_Params *Loaded_params, const char * source)
    {
    	PROCESS_MEMORY_COUNTERS pmc;
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_begin = pmc.PagefileUsage;
     
    	GPU = true;
     
    	ghMutex = OpenMutex(
    		MUTEX_ALL_ACCESS,            // request full access
    		FALSE,                       // handle not inheritable
    		TEXT("GPU_mutex"));
     
    	if (ghMutex == NULL)
    	{
    		ghMutex = CreateMutex(
    			NULL,                        // default security descriptor
    			FALSE,                       // mutex not owned
    			TEXT("GPU_mutex"));  // object name
    	}
    	TransformationStruct.Model_Found = string("");
    	TransformationStruct.NbInlierPoints = -1;
    	TransformationStruct.NbMatchingPoints = -1;
    	TransformationStruct.norm = -1;
    	TransformationStruct.tform = Mat();
    	vect_Matched_Model_keypoints.clear();
    	vect_Matched_Model_keypoints.shrink_to_fit();
    	Model = Loaded_Model;
    	params = Loaded_params;
     
     
    	I = RAD_Image(string(source), GPU);// lecture d'une image + chargement en memoire GPU
     
     
    	if (GPU)WaitForSingleObject(ghMutex, INFINITE);// protection threadSafe SURF descriptor
     
     
    	I.Extract_Features(params, GPU);// calcul des descripteur 
     
     
    	if (GPU)ReleaseMutex(ghMutex);
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_end = pmc.PagefileUsage;
    	long int diff = virtualMemUsedByPRocess_end - virtualMemUsedByPRocess_begin;
    	long double ko = diff / 1024;
    	cout << ko << "     memoire alloué par le constructeur" << endl;
     
    }


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
     
     
    void WorkerBunny::Matching()
    {
     
    	vector< vector<DMatch> > matches;
    	BFMatcher_GPU matcher(NORM_L2);
     
    	Mat indexMat;
    	Mat distMat;
    	PROCESS_MEMORY_COUNTERS pmc;
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_begin = pmc.PagefileUsage;
    	if (GPU)
    	{
     
    		if (strcmp(params->method, "knn"))
    		{
     
    // Force Brute GPU
    			GpuMat trainIdx, distance;
    			vector<DMatch> matches2;
    			Stream stream = Stream();
    			matcher.matchSingle(Model->Model_descriptors_GPU, I.Image_descriptors_GPU, trainIdx, distance, GpuMat(), Stream());//match force brute norme L2
    			stream.waitForCompletion();// execution asynchrone attente des resultats
    			matcher.matchDownload(trainIdx, distance, matches2);
     
    // mise en forme des données
    			indexMat = Mat(matches2.size(), 1, CV_32S);
    			distMat = Mat(matches2.size(), 1, CV_32F);
     
    			for (int k = 0; k < matches2.size(); k++)
    			{
    				indexMat.at<int>(k, 0) = matches2.at(k).trainIdx;
    				distMat.at<float>(k, 0) = matches2.at(k).distance;
    			}
     
    			trainIdx.release(); distance.release();
    			matches2.clear();
    			matches2.shrink_to_fit();
     
     
    		}
    		else
    		{
     
    // knn GPU
    			matcher.knnMatch(Model->Model_descriptors_GPU, I.Image_descriptors_GPU,
    				matches, 2, GpuMat(), false);
     
     
    			distMat = Mat(matches.size(), 2, CV_32F);
    			indexMat = Mat(matches.size(), 2, CV_32S);
    			for (int k = 0; k < matches.size(); k++)
    			{
    				distMat.at<float>(k, 0) = matches.at(k).at(0).distance;
    				distMat.at<float>(k, 1) = matches.at(k).at(1).distance;
    				indexMat.at<int>(k, 0) = matches.at(k).at(0).trainIdx;
    				indexMat.at<int>(k, 1) = matches.at(k).at(1).trainIdx;
    			}
     
     
    		}
     
     
    	}
    	else
    	{
    // mode CPU knn 
     
    		cvflann::flann_distance_t distType;
     
    		if (params->metric == "ssd")
    		{
    			distType = cvflann::FLANN_DIST_L2;
    		}
    		else
    		{
    			distType = cvflann::FLANN_DIST_L1;
    		}
    		flann::Index index(I.Image_descriptors, cv::flann::KDTreeIndexParams(), distType);
    		index.knnSearch(Model->Model_descriptors, indexMat, distMat, 2, flann::SearchParams());
    	}
     
    	matches.clear();
    	matches.shrink_to_fit();
    	matcher.clear();
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_end = pmc.PagefileUsage;
    	long double diff = (virtualMemUsedByPRocess_end - virtualMemUsedByPRocess_begin) / 1024;
     
     
    	/*GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	virtualMemUsedByPRocess_begin = pmc.PagefileUsage;
    	*/
    	vector<int> GoodMatchIndex = RemoveWeakMatches(distMat, params->method, GPU);// garder les match inférieur au seuil
     
     
     
     
    	vector<KeyPoint> Matched_Model_keypoints, Matched_Image_keypoints;
    	vector<int> Index_Model_Matched;
    	vector<MatchingPointStruct>vect_Matched_Model_keypoints_tmp;
    	MatchingPointStruct cur;
    // mise en forme des données en fonction du dictionnaire de Model.
    	int index_old = 0, index_cur = 0;
    	for (int k = 0; k < GoodMatchIndex.size(); k++)
    	{
     
    		Matched_Model_keypoints.push_back(Model->Model_keypoints.at(GoodMatchIndex.at(k)));
    		Matched_Image_keypoints.push_back(I.Image_keypoints.at(indexMat.at<int>(GoodMatchIndex.at(k), 0)));
    		Index_Model_Matched.push_back(Model->Index_Model.at(GoodMatchIndex.at(k)));
    		index_cur = Model->Index_Model.at(GoodMatchIndex.at(k));
    		if (index_cur != index_old)
    		{
    			if (k != 0)
    			{
    				vect_Matched_Model_keypoints_tmp.push_back(cur);
    			}
     
    			index_old = index_cur;
    			cur.vect_Model_KeyPoint.clear();
    			cur.vect_Model_KeyPoint.shrink_to_fit();
    			cur.vect_Image_KeyPoint.clear();
    			cur.vect_Image_KeyPoint.shrink_to_fit();
    			cur.Name = Model->SubModel_Name.at(index_cur - 1);
    			cur.index = index_cur;
    			cur.vect_Model_KeyPoint.push_back(Model->Model_keypoints.at(GoodMatchIndex.at(k)));
    			cur.vect_Image_KeyPoint.push_back(I.Image_keypoints.at(indexMat.at<int>(GoodMatchIndex.at(k), 0)));
     
    		}
    		else
    		{
    			cur.vect_Model_KeyPoint.push_back(Model->Model_keypoints.at(GoodMatchIndex.at(k)));
    			cur.vect_Image_KeyPoint.push_back(I.Image_keypoints.at(indexMat.at<int>(GoodMatchIndex.at(k), 0)));
    		}
     
     
     
    	}
     
    	vect_Matched_Model_keypoints_tmp.push_back(cur);
     
    	distMat.release();
    	indexMat.release();
    	GoodMatchIndex.clear();
    	GoodMatchIndex.shrink_to_fit();
     
     
     
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	virtualMemUsedByPRocess_end = pmc.PagefileUsage;
    	long double diff1 = (virtualMemUsedByPRocess_end - virtualMemUsedByPRocess_begin) / 1024;
     
    	vector<MatchingPointStruct>vect_Matched_Model_keypoints_sorted;
    	vector<int> nbPointsImage;
     
    	for (int k = 0; k < vect_Matched_Model_keypoints_tmp.size(); k++)
    	{
    		vector<KeyPoint> tmp = vect_Matched_Model_keypoints_tmp.at(k).vect_Image_KeyPoint;
    		sort(tmp.begin(), tmp.end(), sort_metric);
     
    		for (int j = 1; j < tmp.size(); j++)
    		{
    			if (tmp.at(j - 1).pt.x == tmp.at(j).pt.x &&
    				tmp.at(j - 1).pt.y == tmp.at(j).pt.y &&
    				tmp.at(j - 1).response == tmp.at(j).response &&
    				tmp.at(j - 1).size == tmp.at(j).size)
    			{
    				tmp.erase(tmp.begin() + j);
     
    			}
    		}
     
    		if (k == 0)
    		{
    			vect_Matched_Model_keypoints_sorted.push_back(vect_Matched_Model_keypoints_tmp.at(k));
    			nbPointsImage.push_back(tmp.size());
    		}
    		else
    		{
    			bool assign = false;
    			for (int i = 0; i < nbPointsImage.size(); i++)
    			{
     
    				if (nbPointsImage.at(i) < tmp.size())
    				{
    					nbPointsImage.insert(nbPointsImage.begin() + i, tmp.size());
    					vect_Matched_Model_keypoints_sorted.insert(vect_Matched_Model_keypoints_sorted.begin() + i, vect_Matched_Model_keypoints_tmp.at(k));
    					assign = true;
    					break;
    				}
     
     
    			}
    			if (!assign)
    			{
    				nbPointsImage.push_back(tmp.size());
    				vect_Matched_Model_keypoints_sorted.push_back(vect_Matched_Model_keypoints_tmp.at(k));
     
    			}
    		}
    		tmp.clear();
    		tmp.shrink_to_fit();
     
    	}
     
     
     
     
    	Matched_Model_keypoints.clear();
    	Matched_Image_keypoints.clear();
    	Index_Model_Matched.clear();
    	vect_Matched_Model_keypoints_tmp.clear();
     
    	nbPointsImage.clear();
    	Matched_Model_keypoints.shrink_to_fit();
    	Matched_Image_keypoints.shrink_to_fit();
    	Index_Model_Matched.shrink_to_fit();
    	vect_Matched_Model_keypoints_tmp.shrink_to_fit();
     
    	nbPointsImage.shrink_to_fit();
     
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	virtualMemUsedByPRocess_end = pmc.PagefileUsage;
     
     
    	long double diff2 = (virtualMemUsedByPRocess_end - virtualMemUsedByPRocess_begin) / 1024;
     
    // tri + seuillage des modeles potentiels
    	vector<MatchingPointStruct> vect_Matched_Model_keypoints_sorted_end;
    	for (int k = 0; k < vect_Matched_Model_keypoints_sorted.size(); k++)
    	{
    		if (vect_Matched_Model_keypoints_sorted.at(k).vect_Model_KeyPoint.size() > params->InlierModelPointSeuil)
    		{
    			vect_Matched_Model_keypoints_sorted_end.push_back(vect_Matched_Model_keypoints_sorted.at(k));
    		}
    	}
     
    	vect_Matched_Model_keypoints_sorted.clear();
    	vect_Matched_Model_keypoints_sorted.shrink_to_fit();
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	virtualMemUsedByPRocess_end = pmc.PagefileUsage;
     
    	long double diff3 = (virtualMemUsedByPRocess_end - virtualMemUsedByPRocess_begin) / 1024;
     
     
    	vect_Matched_Model_keypoints = vect_Matched_Model_keypoints_sorted_end;
    	vect_Matched_Model_keypoints_sorted_end.clear();
    	vect_Matched_Model_keypoints_sorted_end.shrink_to_fit();
    	return;// vect_Matched_Model_keypoints_sorted_end;
     
     
    }
    estimation de la transformation
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
     
    void  WorkerBunny::EstimateTransformation()
    {
     
    	vector<Point2f> Model_Points, Image_Points, Inlier_Model_Points, Inlier_Image_Points;
    	vector<Point3f> Model_Points3d, Image_Points3d;
    	vector<uchar> Inlier_Points;
    	Mat tform, Mask, Mask2, tform_tmp(2, 2, CV_64F), tform2(3, 4, CV_64F);
    	vector<int> NumberInlierPoint;
     
     
     
    	for (int k = 0; k < vect_Matched_Model_keypoints.size(); k++)
    	{
    // pour chaque modeles possible
    		//PROCESS_MEMORY_COUNTERS pmc;
    		//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    		//SIZE_T virtualMemUsedByPRocess_begin = pmc.PagefileUsage;
     
    		Model_Points.clear();
    		Image_Points.clear();
    		Inlier_Model_Points.clear();
    		Inlier_Image_Points.clear();
    		Model_Points.shrink_to_fit();
    		Image_Points.shrink_to_fit();
    		Inlier_Model_Points.shrink_to_fit();
    		Inlier_Image_Points.shrink_to_fit();
    // mise en forme des données
    		for (int j = 0; j < vect_Matched_Model_keypoints.at(k).vect_Model_KeyPoint.size(); j++)
    		{
    			Model_Points.push_back(vect_Matched_Model_keypoints.at(k).vect_Model_KeyPoint.at(j).pt);
    			Image_Points.push_back(vect_Matched_Model_keypoints.at(k).vect_Image_KeyPoint.at(j).pt);
    		}
    		//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    		//SIZE_T virtualMemUsedByPRocess_end1 = pmc.PagefileUsage;
    		//long int diff1 = virtualMemUsedByPRocess_end1 - virtualMemUsedByPRocess_begin;
    		//long double ko1 = diff1 / 1024;
     
     
    		float ratio = ((float)params->InlierImagePointSeuil - 1) / Model_Points.size();
    		int* Good_Match_idx = (int*)malloc(Model_Points.size()*sizeof(int));
    		//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    		//SIZE_T virtualMemUsedByPRocess_end2 = pmc.PagefileUsage;
    		//long int diff2 = virtualMemUsedByPRocess_end2 - virtualMemUsedByPRocess_begin;
    		//long double ko2 = diff2 / 1024;
    // estomation de la transformation
    		tform = estimateRigidTransform_custom(Model_Points, Image_Points, false, MAX(2000, MIN(Model_Points.size() * 2, 10000)), 3, ratio, Good_Match_idx, params->ReprojectionThreshold);
     
     
     
    		//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    		//SIZE_T virtualMemUsedByPRocess_end3 = pmc.PagefileUsage;
    		//long int diff3 = virtualMemUsedByPRocess_end3 - virtualMemUsedByPRocess_begin;
    		//long double ko3 = diff3 / 1024;
     
    		//	Transform_Struct result = estimateRigidTransform_own(Model_Points, Image_Points, 2000, params->ReprojectionThreshold, 3, 0.70);
    		//	tform = result.tform;
    		//	for (int i = 0; i < result.Matchok.size();i++)Good_Match_idx[i] = result.Matchok.at(i);
    		//tform = findHomography_custom();
     
    // Validation de la transformation
    		if (!tform.empty())
    		{
    			//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			//SIZE_T virtualMemUsedByPRocess_tformempty = pmc.PagefileUsage;
     
    			double* ptr0 = tform_tmp.ptr<double>(0);
    			double* ptr1 = tform_tmp.ptr<double>(1);
    			double val = tform.at<double>(0, 0);;
    			ptr0[0] = tform.at<double>(0, 0);
    			ptr0[1] = tform.at<double>(0, 1);
    			ptr1[0] = tform.at<double>(1, 0);
    			ptr1[1] = tform.at<double>(1, 1);
     
    			int sum = 0;
    			for (int j = 0; j < Model_Points.size(); j++)
    			{
    				if (Good_Match_idx[j])
    				{
    					Inlier_Model_Points.push_back(Model_Points.at(j));
    					Inlier_Image_Points.push_back(Image_Points.at(j));
    					sum++;
    				}
     
    			}
    			NumberInlierPoint.push_back(sum);
    			free(Good_Match_idx);
     
    			//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			//SIZE_T virtualMemUsedByPRocess_end4 = pmc.PagefileUsage;
    			//long int diff4 = virtualMemUsedByPRocess_end4 - virtualMemUsedByPRocess_begin;
    			//long double ko4 = diff4 / 1024;
    			//cout << "k = " << k << " ko4 = " << ko4 << endl;
    			int Nb_unique_inlier = 0;
    			for (int j = 0; j < Inlier_Image_Points.size(); j++)
    			{
     
    				for (int i = j; i < Inlier_Image_Points.size(); i++)
    				{
    					bool x = (Inlier_Image_Points.at(j).x == Inlier_Image_Points.at(i).x);
    					bool y = (Inlier_Image_Points.at(j).y == Inlier_Image_Points.at(i).y);
    					if (x && y)
    					{
    						Inlier_Image_Points.erase(Inlier_Image_Points.begin() + j);
     
    					}
     
    				}
     
    			}
     
    			//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			//SIZE_T virtualMemUsedByPRocess_end5 = pmc.PagefileUsage;
    			//long int diff5 = virtualMemUsedByPRocess_end5 - virtualMemUsedByPRocess_begin;
    			//long double ko5 = diff5 / 1024;
     
     
    			float n = norm(tform_tmp, NORM_L2);
     
    			if (n < params->TransformSeuil &&  n > 1 / params->TransformSeuil && Inlier_Image_Points.size() > params->InlierImagePointSeuil &&  Inlier_Model_Points.size() > params->InlierModelPointSeuil)
    			{
    			// si transformation ok on stop
    				TransformationStruct.Model_Found = vect_Matched_Model_keypoints.at(k).Name;
    				TransformationStruct.NbMatchingPoints = vect_Matched_Model_keypoints.at(k).vect_Model_KeyPoint.size();
    				TransformationStruct.NbInlierPoints = Inlier_Image_Points.size();
    				TransformationStruct.norm = n;
     
    				Model_Points.clear(); Image_Points.clear();
    				Inlier_Model_Points.clear(); Inlier_Image_Points.clear();
    				Model_Points3d.clear(), Image_Points3d.clear();
    				Inlier_Points.clear();
    				Model_Points.shrink_to_fit(); Image_Points.shrink_to_fit();
    				Inlier_Model_Points.shrink_to_fit(); Inlier_Image_Points.shrink_to_fit();
    				Model_Points3d.shrink_to_fit(), Image_Points3d.shrink_to_fit();
    				Inlier_Points.shrink_to_fit();
    				tform.release(); Mask.release(); Mask2.release(); tform_tmp.release(); tform2.release();
    				NumberInlierPoint.clear();
    				NumberInlierPoint.shrink_to_fit();
     
    				//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    				//SIZE_T virtualMemUsedByPRocess_end6 = pmc.PagefileUsage;
    				//long int diff6 = virtualMemUsedByPRocess_end6 - virtualMemUsedByPRocess_begin;
    				//long double ko6 = diff6 / 1024;
    				//cout << "k = " << k << " ko6 = " << ko6 << endl;
     
    				//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    				//SIZE_T virtualMemUsedByPRocess_tformempty_end = pmc.PagefileUsage;
    				//long int diff7 = virtualMemUsedByPRocess_tformempty_end - virtualMemUsedByPRocess_tformempty;
    				//long double ko7 = diff7 / 1024;
    				//cout << "inside if k = " << k << " ko7_ok = " << ko7 << endl;
     
     
    				return;// Transformation_Struct;
    			}
     
     
    			//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    			//SIZE_T virtualMemUsedByPRocess_tformempty_end = pmc.PagefileUsage;
    			//long int diff7 = virtualMemUsedByPRocess_tformempty_end - virtualMemUsedByPRocess_tformempty;
    			//long double ko7 = diff7 / 1024;
    			//cout << "inside if k = " << k << " ko7 = " << ko7 << endl;
    		}
    		tform.release();
    		//GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    		//SIZE_T virtualMemUsedByPRocess_end6 = pmc.PagefileUsage;
    		//long int diff6 = virtualMemUsedByPRocess_end6 - virtualMemUsedByPRocess_begin;
    		//long double ko6 = diff6 / 1024;
    		//cout << "k = " << k << " ko6 = " << ko6 << endl;
     
    	}
     
     
    	TransformationStruct.Model_Found = "";
    	TransformationStruct.NbInlierPoints = -1;
    	TransformationStruct.NbMatchingPoints = -1;
    	TransformationStruct.norm = -1;
    	TransformationStruct.tform = NULL;
     
    	Model_Points.clear(); Image_Points.clear();
    	Inlier_Model_Points.clear(); Inlier_Image_Points.clear();
    	Model_Points3d.clear(), Image_Points3d.clear();
    	Inlier_Points.clear();
    	Model_Points.shrink_to_fit(); Image_Points.shrink_to_fit();
    	Inlier_Model_Points.shrink_to_fit(); Inlier_Image_Points.shrink_to_fit();
    	Model_Points3d.shrink_to_fit(), Image_Points3d.shrink_to_fit();
    	Inlier_Points.shrink_to_fit();
    	tform.release(); Mask.release(); Mask2.release(); tform_tmp.release(); tform2.release();
    	NumberInlierPoint.clear();
    	NumberInlierPoint.shrink_to_fit();
     
     
     
     
    	return;// Transformation_Struct;
     
    }


    function ReleaseMemory
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
     
    void WorkerBunny::ReleaseMemory()
    {
    // supprime les objet dans la classe
     
    	PROCESS_MEMORY_COUNTERS pmc;
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_beforeConstructeurClean_constructor = pmc.PagefileUsage;
    // alloué dans le constructeur
    	I.I_cur.release();
    	I.I_cur_GPU.release();
    	I.Image_descriptors.release();
    	I.Image_descriptors_GPU.release();
    	I.Image_keypoints.clear();
    	I.Image_keypoints.shrink_to_fit();
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_AfterExtractionClean_constructor = pmc.PagefileUsage;
    	long int diff2 = virtualMemUsedByPRocess_beforeConstructeurClean_constructor - virtualMemUsedByPRocess_AfterExtractionClean_constructor;
    	double ko2 = diff2 / 1024;
    	cout << ko2 << "     Mémoire constructeurdésallouée                 " << endl;
    // alloué dans Matching
    	vect_Matched_Model_keypoints.clear();
    	vect_Matched_Model_keypoints.shrink_to_fit();
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_AfterMatchingClean_constructor = pmc.PagefileUsage;
    	long int diff3 = virtualMemUsedByPRocess_AfterExtractionClean_constructor - virtualMemUsedByPRocess_AfterMatchingClean_constructor;
    	double ko3 = diff3 / 1024;
    	cout << ko3 << "     Mémoire Matching désallouée                  " << endl;
    // alloué dans EstimationTransformation
    	TransformationStruct.tform.release();
    	TransformationStruct.Model_Found.clear();
    	TransformationStruct.Model_Found.shrink_to_fit();
     
    	GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
    	SIZE_T virtualMemUsedByPRocess_AfterTransformationClean_constructor = pmc.PagefileUsage;
    	long int diff4 = virtualMemUsedByPRocess_AfterMatchingClean_constructor - virtualMemUsedByPRocess_AfterTransformationClean_constructor;
    	double ko4 = diff4 / 1024;
    	cout << ko4 << "     Mémoire Transformation désallouée     " << endl;
     
     
    }
    c'est très perturbant pour moi que la simple présence d'une fonction a la compilation puisse faire fuir les autres....

  4. #4
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 074
    Points : 12 120
    Points
    12 120
    Par défaut
    Votre méthode de tracking mémoire est très primaire.
    Vous ne prenez pas en compte les optimisations de traitement de la C-Runtime, etc...
    Utilisez les outils de tracking mémoire offerts par la libC en Debug de M$, ou des outils dédiés à cette tâche.

    https://msdn.microsoft.com/fr-fr/lib...or=-2147217396

    https://vld.codeplex.com/

  5. #5
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    L'appel à free(Good_Match_Idx) n'a lieu que si !tform.empty().
    D'ailleurs, pourquoi utiliser un malloc()+free() au lieu d'un vecteur d'entiers?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  6. #6
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    265
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 265
    Points : 352
    Points
    352
    Par défaut
    uniquement pour ne pas trop modifier le code OpenCV qui se cache derrière mais effectivement un vecteur serait plus propre
    merci pour la coquille sur ce free.

    j'ai pu corriger la plus grosse partie du problème. et je pense que tu viens de m'indiquer la dernière fuite qu'il me restait a trouver .

    par contre je n'ai toujours pas compris le comportement de mon code.
    la fonction qui posait problème est tform = estimateRigidTransform_custom(Model_Points, Image_Points, false, MAX(2000, MIN(Model_Points.size() * 2, 10000)), 3, ratio, Good_Match_idx, params->ReprojectionThreshold);
    qui fait partie de opencv_video2413.dll
    cette fonction c'est moi qui l'ai modifié (reprise a partir de la fonction OpenCV estimateRigidTransform que j'ai modifié pour pouvoir sortir des paramètres et des infos).
    comment une fuite dans cette fonction de cette dll peut engendrer des fuites dans d'autre fonction (sachant que comme c'est une fonction a moi elle n'est assurément pas appelé ailleurs)


    edit : merci bacelar pour les liens

  7. #7
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Citation Envoyé par gpcbitnik38 Voir le message
    uniquement pour ne pas trop modifier le code OpenCV qui se cache derrière mais effectivement un vecteur serait plus propre
    Si t'as besoin d'un tableau, vector s'utilise exactement de la même manière que ton malloc. Il suffit de le resize au préalable si nécessaire et t'as une zone mémoire contigüe identique.
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  8. #8
    Membre éprouvé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    780
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2006
    Messages : 780
    Points : 1 176
    Points
    1 176
    Par défaut
    En OpenCV 2.4 ya déjà un gros backend C++, c'est ça que tu devrais utiliser si tu maitrise pas les allocations dynamiques etc..

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comportement mémoires des dll linkées ou externes ?
    Par lpierard dans le forum Visual C++
    Réponses: 2
    Dernier message: 26/11/2009, 01h21
  2. Comportement d'allocation mémoire
    Par yanyin dans le forum C
    Réponses: 25
    Dernier message: 09/05/2008, 11h22
  3. [TOMCAT5.5] Comportement curieux de la mémoire
    Par tnodev dans le forum Tomcat et TomEE
    Réponses: 1
    Dernier message: 02/11/2007, 11h26
  4. Allocation/Desallocation de mémoire
    Par Myth_Titans dans le forum C++
    Réponses: 19
    Dernier message: 17/05/2006, 17h41
  5. [Stratégie]Allocation/Desallocation mémoire
    Par lefait dans le forum Langage
    Réponses: 1
    Dernier message: 08/03/2006, 10h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo