Resource leak

From Appmethod Topics
Jump to: navigation, search

Go Up to CodeGuard Errors Index

A Resource Leak error occurs when a resource such as memory is allocated but never deallocated. For most of the objects in the VCL, deallocation is handled automatically, so resource leak errors will most often occur when you allocate a custom area of memory or dynamically create a custom object. The code sample shows an object creation with the memory not being deallocated.

#include <tchar.h>
#pragma hdrstop
#include<stdio.h>
#include<dir.h>
#include <tchar.h>
#pragma hdrstop
class someclass{
	int fnumber;
  public:
	int getnumber(){return fnumber;}
	void setnumber(int nw){fnumber = nw;}
	int doublev(int val){return val*2;}
	int publicalval;

};




void myf()
{
	someclass *myc = new someclass(); // error
}

int _tmain(int argc, _TCHAR* argv[])
{
	myf();
	return 0;
}