Hey,
this is related to absolutely nothing in particular and is of no
importance whatsoever except for my curiousity.
Does anybody have an example of a particularly tricky memory leak
that's hard to spot. I'd like to see something that's a little unusual
or obscure. something that involves some in depth knowledge about
functionality X or scenario X and that causes a memory leak. Something
that would be really easy to miss.
This is simply for curiousity sake and nothing more. if anybody has a
little code snippit or example I'd love to see it
cheers
G 12 1351 Gr*****@nospam. com wrote: Hey,
this is related to absolutely nothing in particular and is of no importance whatsoever except for my curiousity.
Does anybody have an example of a particularly tricky memory leak that's hard to spot. I'd like to see something that's a little unusual or obscure. something that involves some in depth knowledge about functionality X or scenario X and that causes a memory leak. Something that would be really easy to miss.
This is simply for curiousity sake and nothing more. if anybody has a little code snippit or example I'd love to see it
cheers
G
Mixing allocators with wrong deallocators can be easy to miss. (new[]
with delete), (new with delete[]), (new with free), etc....
Example:
int *i = new int(123); //This does NOT create an array
delete[] i; //Wrong deallocator
thanks, nice start. I would have spotted that one. I'm after one I
would NOT have spotted.... a really tricky one. Thanks though, I'm
compiling a list.
(non) virtual destructors in base classes is a good one, I already have
that.
any others...not run of the mill stuff.
cheers
Graham Gr*****@nospam. com wrote: Hey,
this is related to absolutely nothing in particular and is of no importance whatsoever except for my curiousity.
Does anybody have an example of a particularly tricky memory leak that's hard to spot. I'd like to see something that's a little unusual or obscure. something that involves some in depth knowledge about functionality X or scenario X and that causes a memory leak. Something that would be really easy to miss.
This is simply for curiousity sake and nothing more. if anybody has a little code snippit or example I'd love to see it
Well, ADL can change the meaning of a function call silently:
namespace N
{
class C{};
void f(C c, int i)
{
// deletes things
}
}
int main()
{
N::C c;
f(c, 1.0); // may give a conversion warning
}
Adding the global function
void f(C c, double d);
changes the meaning of the call to f(). If N::f() was in charge of
deleting things, you may be suprised.
Jonathan Gr*****@nospam. com wrote: Hey,
this is related to absolutely nothing in particular and is of no importance whatsoever except for my curiousity.
Does anybody have an example of a particularly tricky memory leak that's hard to spot. I'd like to see something that's a little unusual or obscure. something that involves some in depth knowledge about functionality X or scenario X and that causes a memory leak. Something that would be really easy to miss.
This is simply for curiousity sake and nothing more. if anybody has a little code snippit or example I'd love to see it
cheers
G
How about this
class Dodgy
{
Dodgy() : ptr(new char[99]) {}
~Dodgy() { delete[] ptr; }
char* ptr;
X x;
};
If the X constructor throws an exception then the memory allocated will
never get freed, even through the destructor does free the memory. This
is because in this case the destructor for Dodgy is never called.
john Gr*****@nospam. com wrote: thanks, nice start. I would have spotted that one. I'm after one I would NOT have spotted.... a really tricky one. Thanks though, I'm compiling a list.
(non) virtual destructors in base classes is a good one, I already have that.
any others...not run of the mill stuff.
cheers
Graham
Niether of your two exmaples are memory leaks, they are undefined
behaviour. A memory leak is one possibility but not the only one (or
even the most likely one).
john
thanks for that... undefined behaviour is ok too. Good point though...
I've noted that point.
cheers
G
John Harrison wrote: Gr*****@nospam. com wrote:
Hey,
this is related to absolutely nothing in particular and is of no importance whatsoever except for my curiousity.
Does anybody have an example of a particularly tricky memory leak that's hard to spot. I'd like to see something that's a little unusual or obscure. something that involves some in depth knowledge about functionality X or scenario X and that causes a memory leak. Something that would be really easy to miss.
This is simply for curiousity sake and nothing more. if anybody has a little code snippit or example I'd love to see it
cheers
G
How about this
class Dodgy { Dodgy() : ptr(new char[99]) {} ~Dodgy() { delete[] ptr; } char* ptr; X x; };
If the X constructor throws an exception then the memory allocated will never get freed, even through the destructor does free the memory. This is because in this case the destructor for Dodgy is never called.
john
But this version is OK
class NotDodgy
{
NotDodgy() : ptr(new char[99]) {}
~NotDodgy() { delete[] ptr; }
X x;
char* ptr;
};
No memory leaks there.
john Gr*****@nospam. com wrote: ?
The difference is the order of construction. If the X constructor is
called after the allocation of memory and the X constructor throws then
you have a memory leak. But in the second example the X constructor is
called before the memory allocation (because of the different order of
declarations) therefore when the X constructor throws the memory
allocation hasn't happened yet.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ranjeet.gupta |
last post by:
Dear All
Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.
Juts Theoritical Assumtion below:
|
by: José Joye |
last post by:
Hi,
I have implemented a Service that is responsible for getting messages from a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I...
|
by: Don Nell |
last post by:
Hello
Why is there a memory leak when this code is executed.
for(;;)
{
ManagementScope scope = new ManagementScope();
scope.Options.Username="username";
scope.Options.Password="password";
scope.Path.Path=@"\\pc\root\cimv2";
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex matches are called
within a loop (like if or for). E.g.
for(int i = 0; i < 10; i++)
{
Regex r = new Regex();
|
by: James |
last post by:
The following code will create memory leaks!!!
using System;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
namespace MemoryLeak
| |
by: Adrian |
last post by:
Hi
I have a JS program that runs localy (under IE6 only) on a PC but it has
a memory leak (probably the known MS one!)
What applications are there that I could use to look at the memory usage of
each object within my JS app to help locate my problem?
Thanks
|
by: Salvador |
last post by:
Hi,
I am using WMI to gather information about different computers (using win2K
and win 2K3), checking common classes and also WMI load balance. My
application runs every 1 minute and reports the status of the machines.
Upon we follow the .NET object lifetime recommendations the application is
constantly consuming more memory! The problem is on the
ManagementObjectSearch, upon we Dispose the object it seems that is not
releasing the...
|
by: Jim Land |
last post by:
Jack Slocum claims here
http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript-
memory-leaks/
that "almost every site you visit that uses JavaScript is leaking memory".
Anybody know anything about this?
Does *Javascript* leak memeory, or
does the *browser* leak memory?
|
by: Ragnar Agustsson |
last post by:
Hi all
I have been wandering about the best way to sandbox memory leaks in 3rd
party libraries when using them from the .Net framework.
I have a 3rd party library, written in C++, that leaks a lot of memory
but I still had to use it.
1.
After using DLLImport and seeing the memory leak I tried to load and
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |