Memory, heap, stack, malloc...fun.

8 posts / 0 new
Last post
KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:
Memory, heap, stack, malloc...fun.

Hi, i'm getting a couple of error's and i think it's memory related. I've read of the helpful topics here, http://www.mosync.com/content/ran-out-heap-memory & article here, http://www.mosync.com/blog/2010/11/quick-note-memory-alignment-errors. Having come from a c++ background (one of the reason i chose mosync :)) i understand basic memory management, new and delete, the heap and the stack.

The error i'm getting is as follows.

[1] MoSync Panic 40003. "Resource handle out of bounds" The panic occurred in the syscall maDestroyObject.

I've nailed this down to two simple lines of code. in the main class i'm doing this;

m_IndexScreen = new IndexScreen(this);

indexscreen is another class which setups the next screen (works fine).

But when i add this line in my main class destructor.

delete m_IndexScreen;

when quitting my application i get the above error. Very stange.

Strange still because this morning i had this code in (and more) and it worked fine, but another errror i was having caused me to reduce all code back to the simplest form, to see if i could find that error. If anyone could give me an idea on that i would be grateful.

NOW the real crux of a problem i'm having.

"Malloc failed. You most likely ran out of heap memory. Try to increase the heap size."

As i said i read the above linked topic, increased my Heap, stack and data sizes. Ran the code, there seems to be enough memory and i've very careful with my clean up. I clean up all parent widgets (deleting children with them) and all new's that are created. There mainly for new screens.

I'm making a very basic page by page information app, with a couple images and text on it, nothing ground breaking. This problem only seems to come about when i added my 6th page. So too much memory usage makes sense. I can only assume i have memory leak somewhere or i'm missing a trick.

I'm gonna attach what i've done so far. If anyone can help i'd appredicate it.

Thanks Kyle.

AttachmentSize
NetherInnAndroid.rar645.31 KB
NetherInnAndroid.zip650 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

If you can add your project as a zip file then I'll look at it.

KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:

attached to the orginal post. Any help you can give me is appreciated. Just out of interest, why zip over rar, just not a fan or some more astute reason?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

I don't run any anti-virus, and I don't need to. I only open attachments in email I'm expecting; I never click on a popup; I use an ad-blocker and I never open a rar file. I think that there is too much bad stuff people hide in rar, so if I have a policy of *never* opening rar files, then I can never be caught out. There is never good reason to use rar - zip is more convenient, and 7z gives better compression.

Once every couple of years or so I get curious and run a virus scan - it never finds anything other than some cookies it doesn't like. So this policy means I have no need for anti-virus, and I run windows. Actually, I think that most anti-virus is a scam.

Anyway, thanks for the zip. I might not get to it before tomorrow morning now though.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Morning, found this straightaway:

WhatsOnScreen::WhatsOnScreen(Screen *previous) : previous(previous)
{
	m_MainLayout = new Label(0, 0, scrWidth, scrHeight, NULL);
	m_MainLayout->setSkin(NULL);
	m_MainLayout->setDrawBackground(true);
	m_MainLayout->setBackgroundColor(0xFEF011);

	m_QuizScreen = new QuizScreen(this);
	m_EnergizerScreen = new WhatsOnScreen(this);

The last line is the important one.  When you create a WhatsOn screen, it creates another one.  When the second one creates, it creates a third one.  The third one creates a fourth and so on until you run out of memory.

Also, I'd like to show you DualUI which is part of AppMancer.  It has a more comprehensive starting point for apps than MAUIex, plus you can also build to NativeUI components on Android and iOS, and widgets on other platforms.  Have a look at http://appmancer.com/index.php/sdk/amui/item/86-dualui.html and http://www.mosync.com/content/dualui-native-and-non-native-ui-single-source

KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:

this is what another set of eyes does for you. a rookie mistake but sometimes they slip through. Really annoying but still. I'll have a look into that appmancer thing. I don't have much time mon-fri so it'll probably be next weekend.

KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:

Ok so that fixed the Malloc problem of it telling me my memory was screwed. I realised i didn't say what the problem was that Sam kindly pointed out.

m_EnergizerScreen = new WhatsOnScreen(this); = m_EnergizerScreen = new EnergizerScreen(this);

making a copy of the class your in, not a good idea....recursive death.

anyway, i changed that but when i quit out, i'm still getting the "MoSync Panic 40003. "Resource handle out of bounds" The panic occurred in the syscall maDestroyObject." error. Looks like a resource isn't cleaned properly, as it's when i'm quitting out i'd expect thats within the main menu, i'll try tonight to have a close eyeball of my code, but just in case anyone fancied a go :)

Now as i said i'm gonna look into the appmancer thing and that might eliminate the problem, but its for anyone using maui that has a similar problem.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

It sounds like you're either trying to use a resource (a picture?) which you've destroyed with maDestroyObject(), or you're trying to destroy an object twice. I'll have another look at your code in a minute.