|
-
October 30th, 2006, 11:52 PM
#1
Memory Leak
I wrote a program using VC++.
I use the library files (vld.h) to detect the memory leak problem.
I face memory leak problem.
Here is the sample.
char * a;
UCHAR b[100];
.
.
.
a = (char *) b;
std::string c = std::string(a);
Can anyone help me?
Thanks.
-
October 31st, 2006, 12:31 AM
#2
Re: Memory Leak
What is happening in between those lines ( the .... s )
-
October 31st, 2006, 12:47 AM
#3
Re: Memory Leak
In between the lines, I actually access mysql such as select statement or update statement.
Like
- SQLBindCol(hStmt, 1, SQL_C_CHAR, ....
Thanks
-
October 31st, 2006, 03:54 AM
#4
Re: Memory Leak
When Ever use a Pointer in your Program try to use new to Allocate Memory to your pointer and after Finishing your Work use Delete to free allocated memory.
Thanx
-
October 31st, 2006, 03:59 AM
#5
Re: Memory Leak
 Originally Posted by thl
I wrote a program using VC++.
I use the library files (vld.h) to detect the memory leak problem.
I face memory leak problem.
Here is the sample.
char * a;
UCHAR b[100];
.
.
.
a = (char *) b;
std::string c = std::string(a);
Can anyone help me?
Thanks.
You dont have memory allocations done using new or malloc, so there is no leak in this code.
Regards,
Ramkrishna Pawar
-
October 31st, 2006, 08:55 PM
#6
Re: Memory Leak
Thanks everyone.
I would like to show you all that the line that has been complained is
std::string c = std::string( a );
that means the last line that I posted.
Hope to hear more from you all soon....
Thanks
-
October 31st, 2006, 09:01 PM
#7
Re: Memory Leak
 Originally Posted by thl
Thanks everyone.
I would like to show you all that the line that has been complained is
std::string c = std::string( a );
that means the last line that I posted.
There is no memory leak there.
Temporarily get rid of the SQL stuff, post a complete but small program that demonstrates the problem (please, no "..." -- make sure it is a complete example), and post it. Otherwise you do not have information for anyone to tell you what is going on.
Regards.
Paul McKenzie
-
November 6th, 2006, 12:27 AM
#8
Re: Memory Leak
The program is like this,
int main(int argc, char* envp[])
{
int nRetCode = 0;
char * b;
UCHAR a[100] = "hehehe";
b = (char *) a;
string c = string(b);
return nRetCode;
}
There is no memory leak for this, but in my actual applications, after running some lines of the SQL stuffs, it claims memory leak.
Thanks
-
November 6th, 2006, 01:10 AM
#9
Re: Memory Leak
Then it could be in SQL code.
Regards,
Ramkrishna Pawar
-
November 6th, 2006, 01:26 AM
#10
Re: Memory Leak
 Originally Posted by thl
There is no memory leak for this, but in my actual applications, after running some lines of the SQL stuffs, it claims memory leak.
So given this, what is your conclusion? The SQL is the thing you should be investigating.
Regards,
Paul McKenzie
-
November 6th, 2006, 01:49 AM
#11
Re: Memory Leak
It's 'heh heh' 
What claims a memory leak? vld.h? Visual leak detector?
http://www.codeproject.com/tools/vis...select=1236065
Look, unless you know what you are doing, you will get false positives from the CRT. Can you post a complete project. Your code has no 'leak' so I'm gonna assume they call the leak check before the CRT clears.
-
November 8th, 2006, 04:51 AM
#12
Re: Memory Leak
What does it mean by call leak before CRT clear?
Thanks
Last edited by thl; November 8th, 2006 at 04:54 AM.
-
November 8th, 2006, 07:03 PM
#13
Re: Memory Leak
You may also consider using different technology to connect to the mySql database. Consider using the ATL DB Consumer classes or ADO for db interaction. The old direct ODBC approach that you are using (SQLBindCol(hStmt, 1, SQL_C_CHAR, ....)), requires that you explicitly allocate memory for the column data. As such, you must remember to delete any allocated memory or you'll have leaks.
The ATL DB Consumer or ADO approaches take care of any memory allocation/cleanup for you and let you get on to programming other parts of your application.
-
November 9th, 2006, 09:37 PM
#14
Re: Memory Leak
Arjay, thanks a lot. There is a new way for me to move forward.
Just to confirm again, like
****************************
UCHAR ucField[50];
SDWORD sdField;
SQLBindCol(hStmt, 1, SQL_C_CHAR, ucField, sizeof(ucField), &sdField);
****************************
may cause the memory leak?
For what I have in my project, I just do as what I showed above.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|