crash when run out of memory

J

jy

I have a C++ program which is "purify" clean, but crashes (called terminate)
when run out of memory on linux 2.4.27. From the core file, the crashes happen
after I throw an exception (after malloc returns null), and the stack winding
was calling the destructor of a large object. What's the genearl guidlines for
debugging, fixing, or at least making it a graceful exit than a crash?

Thanks,

-jy
 
A

Artie Gold

jy said:
I have a C++ program which is "purify" clean, but crashes (called terminate)
when run out of memory on linux 2.4.27. From the core file, the crashes happen
after I throw an exception (after malloc returns null), and the stack winding
was calling the destructor of a large object. What's the genearl guidlines for
debugging, fixing, or at least making it a graceful exit than a crash?

Thanks,

-jy

Without seeing your code it's impossible to be sure, but I suspect your
problem is platform specific (and due to overcommitment of memory in Linux).

[Followup-To set: news:comp.os.linux.development.apps]

HTH,
--ag
 
K

Karthik Kumar

jy said:
I have a C++ program which is "purify" clean, but crashes (called terminate)
when run out of memory on linux 2.4.27. From the core file, the crashes happen
after I throw an exception (after malloc returns null),

Did you say it is a C++ . Why would you use malloc then ?
Why not new ?
and the stack winding
was calling the destructor of a large object.

Was that large object defined as local to the function ?
Post some code here.
 
?

=?iso-8859-1?Q?Ali_=C7ehreli?=

jy said:
I have a C++ program which is "purify" clean, but crashes (called terminate)
when run out of memory on linux 2.4.27. From the core file, the crashes happen
after I throw an exception (after malloc returns null),

I think it is new that throws the exception, not you. new is likely
using malloc internally and throwing std::bad_alloc when there is no
memory.
and the stack winding
was calling the destructor of a large object. What's the genearl guidlines for
debugging, fixing, or at least making it a graceful exit than a crash?

Catch std::bad_alloc exception in main and report it:

int main()
{
try
{
/* the application code */
}
catch (std::bad_alloc const &)
{
cout << "no memory\n";
}
}

Ali
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,518
Latest member
RomanGratt

Latest Threads

Top