Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9237215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:29:09+00:00 2026-06-18T07:29:09+00:00

I recently discovered that a lot places in our code were doing something like

  • 0

I recently discovered that a lot places in our code were doing something like this:

int * int_array = new int[1000];

// ... do things with int_array

delete int_array;

The problem of course is that it should be using the delete [] operator, not the regular delete operator.

The mystery is: This code has been working for literally years, when compiled by Visual Studio 2003 and 2005 on Windows, and GCC / clang on OS X. Why hasn’t this caused things to go terribly wrong before now?

As I understand it, we’re telling the compiler to deallocate memory the “wrong” way, and usually if you do that, something terrible happens and your program crashes. Why isn’t this happening for us? Do modern compilers automatically “do the right thing” for you, or enough of the right thing that it doesn’t matter for basic types, or something else? I can’t accept that we simply got lucky, as this code has been in use for years, by thousands of customers under multiple different operating systems.

Note that I’m NOT asking for an excuse to do things wrong, just trying to understand why we aren’t in trouble for doing things wrong. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:29:10+00:00Added an answer on June 18, 2026 at 7:29 am

    This is the nature of undefined behavior — it might do exactly what you intended it to do. The problem is, with the next version of the compiler, operating system, library, or CPU … it might do something completely different.

    Most likely, you’re getting away with it for two reasons:

    1. int doesn’t have a destructor. So the failure to correctly destroy each element in the array has no consequences.

    2. On this platform, new and new[] use the same allocator. So you’re not returning a block to the wrong allocator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently discovered that I am affected by this bug http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg71515.html Well, at
I recently discovered that 2 == [2] in JavaScript. As it turns out, this
We have recently discovered that when we run a lot of different processes on
I recently discovered that rails or some other entity is messing up my code
I recently discovered that something compiles(not sure that it's legal though). My need for
I've been writing a lot of code recently that involves interop with the Win32
I recently discovered that all Windows 7 machines have an handwriting recognition API within
I recently discovered that when you have a page set to session readonly and
I recently discovered that I can use lambdas to create simple event handlers. I
I recently discovered that a sql query that was running fine earlier is now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.