#66 Crash in low memory situation

closed
nobody
None
5
2004-04-15
2004-02-26
Anonymous
No

I am just evaluating acdk and wrote a small programm to
test the behaviour in low memory situation. My test
programm crashed with a null pointer exception when
memory went low.

Environment Windows2000, Microsoft Visual Studio 6

Source code of my test program:

#include "stdafx.h"
#include <acdk.h>
#include <acdk/lang/lang_all.h>
#include <acdk/util/arraylist.h>

using namespace acdk::lang;
using namespace acdk::util;

class ACDKTest1
{
public:

static int main(RStringArray args);
};

int ACDKTest1::main
(
RStringArray args
)
{
RArrayList rList = new ArrayList();

int i = 0;
try
{
while(true)
{
rList->add(new Integer(i++));
}
}
catch(RThrowable ex)
{
System::out->println(ex->getMessage());
}

return 0;
}

Call Stack:

acdk::lang::sys::PagedAllocatorPage::_getFreeCapacity
() line 168 + 3 bytes
acdk::lang::sys::PagedAllocatorPage::_hasCapacity(int
100) line 181 + 8 bytes
acdk::lang::sys::PagedAllocator::_allocate(int 80, short
2) line 115 + 18 bytes
acdk::lang::sys::PagedAllocator::allocate(unsigned int
76, acdk::lang::sys::AllocatedType ObjectMem) line 135
+ 20 bytes
acdk::lang::ObjectBase::operator new(unsigned int 76,
acdk::lang::sys::Allocator * 0x00362a58) line 138 + 17
bytes
acdk::util::AbstractList::listIterator(int 0) line 208 + 25
bytes
acdk::util::AbstractList::indexOf(const
RefHolder<acdk::lang::Object> & {...}) line 151 + 41
bytes
acdk::util::Vector::indexOf(const
RefHolder<acdk::lang::Object> & {...}) line 86 + 22
bytes
acdk::util::Vector::removeElement(const
RefHolder<acdk::lang::Object> & {...}) line 263 + 39
bytes
acdk::util::Vector::remove(const
RefHolder<acdk::lang::Object> & {...}) line 134
acdk::lang::ThreadGroup::_removeThread(const
RefHolder<acdk::lang::Thread> & {...}) line 280 + 77
bytes
acdk::lang::Thread::removeSystemThread() line 600 +
51 bytes
acdk::lang::SystemImpl::deinit() line 440
acdk::lang::System::main(int
(RObjectArrayImpl<acdk::lang::RString>)* 0x0040100a
ACDKTest1::main(class RObjectArrayImpl<class
acdk::lang::RString>), int 1, char * * 0x00380fb0, char
* * 0x00381028, const char * * 0x00000000) line 734
main(int 1, char * * 0x00380fb0, char * * 0x00381028)
line 48 + 27 bytes
mainCRTStartup() line 206 + 25 bytes

The watch window of the VS debugger shows that
_last==NULL in
acdk::lang::sys::PagedAllocator::_allocate
and so this==NULL in
acdk::lang::sys::PagedAllocatorPage::_getFreeCapacity

Best regards
Michael (mlorenz@novadys.com)

Discussion

  • Logged In: NO

    OK it's my fault. I debuged a little and found that acdk
    does not check for ::new returning NULL. So I have
    to _set_new_handler and throw my own exception.

    Best regards,
    Michael

     
  • Logged In: YES
    user_id=20586

    Hi,

    Until now I wasn't run into low memory situation.

    But on my feature list for a long time is the posibility to
    limit usage of memory per process or thread basis.
    This is important if used as multithreaded server process,
    where
    the threads calls scripting code (which may be buggy).

    Currently I implement the necessary mechanism.
    In case of low memory - limited via
    System::setMaxMemoryUsage()
    or System::setThreadMaxMemoryUsage() or real low memory
    (new operator returns 0) - the Allocator first try to free
    memory via System::gc(), and if this doesn't help it throws
    a OutOfMemoryError.

    The feature/fix will be in the next Snapshot. In the CVS
    it will be in the next days.

    Regards,
    Roger

     
    • status: open --> closed