Click here to Skip to main content
15,894,539 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Problem with /clr and static lib Pin
Saurabh.Garg28-Sep-08 23:18
Saurabh.Garg28-Sep-08 23:18 
GeneralRe: Problem with /clr and static lib Pin
n1pabs28-Sep-08 23:30
n1pabs28-Sep-08 23:30 
GeneralRe: Problem with /clr and static lib Pin
n1pabs28-Sep-08 23:56
n1pabs28-Sep-08 23:56 
AnswerRe: Problem with /clr and static lib Pin
_AnsHUMAN_ 28-Sep-08 23:18
_AnsHUMAN_ 28-Sep-08 23:18 
Questionmemory leak Pin
SRKSHOME28-Sep-08 20:42
SRKSHOME28-Sep-08 20:42 
AnswerRe: memory leak Pin
Sauce!28-Sep-08 21:09
Sauce!28-Sep-08 21:09 
GeneralRe: memory leak [modified] Pin
SRKSHOME28-Sep-08 21:23
SRKSHOME28-Sep-08 21:23 
GeneralRe: memory leak Pin
Sauce!29-Sep-08 18:07
Sauce!29-Sep-08 18:07 
well in that case you definitely do have a memory leak, as you are allocating memory with new, but you never called delete on it, and have no way to, because it was never assigned to a variable, but instead simply passed directly into a function.

What you should do is allocate memory to a variable using new first, and then pass that variable to the function, like so;

test * theVar = NULL;
theVar = new test(30);
test1->display(theVar);


Then when you are done with theVar call delete on it and assign NULL to it;

delete theVar;
theVar = NULL;


And then you have no memory leak.

Another thing to keep in mind is to check whether or not theVar is NULL before you use it, so back in my original code snippet you would change it to something like this;

test * theVar = NULL;
theVar = new test(30);
if(theVar != NULL)
{
test1->display(theVar);
}
else
{
//error handling code.
}

GeneralRe: memory leak Pin
SRKSHOME29-Sep-08 18:24
SRKSHOME29-Sep-08 18:24 
AnswerRe: memory leak Pin
KarstenK28-Sep-08 21:16
mveKarstenK28-Sep-08 21:16 
AnswerRe: memory leak Pin
_AnsHUMAN_ 28-Sep-08 21:19
_AnsHUMAN_ 28-Sep-08 21:19 
AnswerRe: memory leak Pin
Saurabh.Garg28-Sep-08 21:21
Saurabh.Garg28-Sep-08 21:21 
QuestionArray Size Pin
TeVc++28-Sep-08 20:19
TeVc++28-Sep-08 20:19 
AnswerRe: Array Size Pin
MANISH RASTOGI28-Sep-08 20:33
MANISH RASTOGI28-Sep-08 20:33 
GeneralRe: Array Size Pin
TeVc++28-Sep-08 20:43
TeVc++28-Sep-08 20:43 
GeneralRe: Array Size Pin
MANISH RASTOGI30-Sep-08 18:25
MANISH RASTOGI30-Sep-08 18:25 
AnswerRe: Array Size Pin
ThatsAlok28-Sep-08 20:37
ThatsAlok28-Sep-08 20:37 
GeneralRe: Array Size Pin
TeVc++28-Sep-08 20:52
TeVc++28-Sep-08 20:52 
GeneralRe: Array Size Pin
Sauce!28-Sep-08 21:00
Sauce!28-Sep-08 21:00 
GeneralRe: Array Size Pin
santhoshv8428-Sep-08 21:10
santhoshv8428-Sep-08 21:10 
AnswerRe: Array Size Pin
KarstenK28-Sep-08 21:18
mveKarstenK28-Sep-08 21:18 
QuestionRe: Array Size Pin
CPallini28-Sep-08 21:45
mveCPallini28-Sep-08 21:45 
AnswerRe: Array Size Pin
TeVc++28-Sep-08 22:14
TeVc++28-Sep-08 22:14 
GeneralRe: Array Size Pin
CPallini28-Sep-08 22:24
mveCPallini28-Sep-08 22:24 
GeneralRe: Array Size Pin
TeVc++28-Sep-08 23:25
TeVc++28-Sep-08 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.