Memory Access Violation

Monkey Forums/Monkey Beginners/Memory Access Violation

En929(Posted 2016) [#1]
I was wondering do Monkey-X reach an eventual point to where it runs out of memory to where one can't program anymore things into one's game? I making a large RPG game and it has been going well. But, suddenly I've started getting the Memory Access Violation error message.

Nobuyuki(Posted 2016) [#2]
It's possible to load too many resources at once and get this error when trying to access a resource. You won't get an "out of memory" type error when allocating, but instead the resource will likely silently fail to load and the error will occur when trying to utilize the resource. Be sure to properly dispose of the resources you're not using; There's no surefire way to reliably ensure when the GC will come around to free them.

En929(Posted 2016) [#3]
Nobuyuki, how do I dispose the resources that I'm not using? Is there a particular command in monkey X that I could use to do that? For example, is there a Destroy command because there are indeed some images that I used only one time throughout my game and then I never use them again.

Xaron(Posted 2016) [#4]
You can use Image.Discard for that.

Gerry Quinn(Posted 2016) [#5]
The other possibility is that you are allocating (really) huge data structures and never de-allocating them (which in Monkey means 'forgetting them, i.e. having no references to them), For example, if your game is based on level-maps, but you keep all your old level maps with all their contents alive in a list somewhere.

It might be useful to run Resource Monitor and see what the memory usage graph is like when you run your game for a bit. That may give you a clue as to where the excess usage is.

It doesn't *sound* like a constant memory leak or an individual bug, but those are always possibilities too.

Monkey doesn't have any particular scaling problems as far as I know - it should be able to make a game as big as any out there.

Xaron(Posted 2016) [#6]
True, but especially on mobile platforms you can run into these problems pretty fast. So you can't just do a LoadImage and be sure that this will be persistant over the complete session. I have now some kind of a resource manager where I reload images when they got removed. Better than a crash I guess. ;)

En929(Posted 2016) [#7]
Thanks for all of the responses and help. I figured out what was wrong with my code. I had a prior reference the Enemy class. That is, at first, I named the reference enemy: Enemy (i.e., and called the reference as “enemy.Draw()” and so forth). But, later I changed that same reference to En: Enemy as in “En.Draw()” and so forth, and I forgot to delete the old reference as in enemy.Draw(). Thus, when the computer went looking for the old “enemy” reference that I put inside of the code, it wasn’t listed. Thus, I got the error. I hope this makes sense. Thus, thanks for the help. I’ll come back if I need anymore help.

Gerry Quinn(Posted 2016) [#8]
Of course... and we all goofed in answering you, because we read where you said 'out of memory' and did not notice that the actual error was 'memory access violation', a completely different thing! Glad you found it anyway, even with our 'help' :-D

En929(Posted 2016) [#9]
Gerry, actually at first I didn't know whether the reason that I got the error was because the system ran out of memory or not. Afterall, that was what I originally mentioned. I didn't actually know what the problem truly was and thus you all were correct and great in brainstorming some possibilities. I also asked the original question t because I have A LOT of data in my game and I include A LOT of scanned images too. Heck, I might have ended up asking this question again or eventually if it reaches such point.

But, in this case I found that the reason that I was getting the error wasn't because of an out memory situation (at least not this time), but it was because I overlooked something that I didn't see before. So, you all didn't make any mistakes.I didn't know what Memory Access Violation meant at the time. Plus, I'm no expert at programming. I'm still learning. Hence, was the reason I posted the question. Thanks!

Gerry Quinn(Posted 2016) [#10]
A memory access violation mean the processor tried to get at some memory it isn't supposed to (because it wasn't allocated to the program, or it was allocated and subsequently de-allocated).

En929(Posted 2016) [#11]
Thanks for clarifying that Gerry Quinn