Jump to content

C++ Random Errors


SpiderPig
 Share

Go to solution Solved by Ma-Shell,

Recommended Posts

Lately I've been getting heaps of seemingly random errors.  I traced a few of these problems to memory leaks which is why I started using smart pointers.  But still I get random "Access Violations".  Sometimes it will be inside a Leadwerks function and other times it will be in mine.  I can stop the program and run again without cleaning the solution and it will crash somewhere else or it wont crash at all.

Seems to be random and the only thing I think it could be is memory leaks.  I'm not sure what else could cause random errors like this.  Has anyone had similar problems or know of possible other causes / solutions?

Link to comment
Share on other sites

  • Solution

A memory leak won't cause access violations! A memory leak is when you allocate space on the heap, by using malloc or new and then simply abandon it without ever releasing it with free or delete. Smart pointers should do that sort of management for you and even if you were to do that wrong, it would simply cause the memory used by your program to rise steadily.

An access violation occurs, when you are trying to access memory in a way you're not supposed to. This means, it is either not in an allocated state (never allocated or allocated and then freed) or it has protections active. In most cases, this happens, when you freed some object but did not set all pointers to null. This sort of problem can cause very weird types of errors. In the worst case, the memory you freed is reallocated for a different purpose and the next time you write to it, you modify some completely different structure

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...