Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Does DB have a problem with memory leaks?

Author
Message
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 23rd Jan 2004 22:00
Even when using string commands such as Left$, Right$ and Upper$?

I've spent a considerable amount of time implementing debugging code on all arrays, potential memory consuming functions etc in my project and I cannot find any particular point in the code that can explain the increase of memory usage.

On a per frame basis, using:

Text 0, 0, "FPS: " + Str$( Screen Fps() ) + " Mem: " +Str$( SYSTEM SMEM AVAILABLE() )

Now I've modified this code to show exactly how much the memory usage is consumed every frame and roughtly every 40-60 frames, this goes up by 32768 bytes (32k)

Does anybody know or is aware of such memory leakage with certain commands in DarkBASIC Professional.

I know it isn't specifically aimed at one section of my project because I record memory status at the beginning of each function and compare the difference at function termination. Some of the functions do practically nothing in terms of array allocation or object loading etc, yep the memory status jumps by 32k in usage. Where the hell is this 32k going and what's causing the leak?

Now I can only assume based on specific parts of my project that this is somehow related to string usage or string manipulation functions but some ideas would help

Many thanks.

Paul.


QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 23rd Jan 2004 22:23
The only thing I know of causing memory leaks is having your program dig deeper and deeper as it keeps opening statements and never closing them, such as

label pie
If bob=1
goto pie
endif

Cause it never reaches that endif...and it has to store it's location in the memory, so it opens an if statement, remembers it, then opens another one..and never closes the previous one.

But that was only a problem on graphing calculators...especially considering how little memory they had.

APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 23rd Jan 2004 22:38
It's definately not a recursive problem because besides tracing the call stack, every function exits cleanly, but are you saying that if a label is jumped to from inside an If condition, this supposedly adds to memory consumption. I can't see how that can happen. I do have error conditions that jump to labels contained within the same function, infact:- this is typical of one:



Typically this is certainly no warrent for a loss in 32k of memory. Although the SYSTEM SMEM function used in my previous post, I think this polls no less than 32k but the actual memory usage may be smaller and increasing rapidly, but not being recorded until it hits a 32k boundary.

I'm stumped though.

Paul.


APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 23rd Jan 2004 22:42
What makes it worse is that the Debugger.... well.... need I say more.


APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 23rd Jan 2004 23:01
<Dear oh dear!!! Shaking head>

Right, ok, ok, must remember, not programming in C now, <SLAPS FOREHEAD> Ok, two things that would really be nice addition to the language.

1: Make it TOTALLY IMPOSSIBLE to jump out of one function and into the end of another just becaus you spelt the label incorrectly.

2: Please please please <I BEG YOU> have an OPTION EXPLICIT.

Trying to trace a variable that has one typo in it so it always ends up with ZERO as the value.

<sob>


APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 23rd Jan 2004 23:48
This would be a nice feature for future updates, to either have Catch and Throw error checking in DB, or ON ERROR!

This would rid of label usage altogether <gg>

Paul.


CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 24th Jan 2004 00:10
yes Try-Catch-Finally-End Try blocks would be nice but we then would need some sort of exception or error object.

-RUST-
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 24th Jan 2004 02:17
And there is no chance of CATCH/TRY or ON ERROR either.


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 24th Jan 2004 03:49
I would have been horrified by the idea a while ago, but option explicit is beginning to seem mighty attractive.

--Mouse: Famous (Avatarless) Fighting Furball

I am the chainsaw paladin.
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 24th Jan 2004 04:04
Apex here's a tip, don't sweat over the Memory functions...
they don't call back the right values. Infact sometimes it feels like it just makes the buggers up.

It isn't, it's just the way the TGC have coded them to include the active page memory.
What does this mean exactly?
Probably the fact that they're adding a Dynamic variable into the equasion of something that should be static. - the dynamic physical changes.

But what can you do? Not alot unless you fancy messing around with Windows DLLs


P4-M 1.3Ghz | 512mb DDR PC1800 | GeForce FX 5600 Go! 53.03 | DirectX9.0b SDK | C-Media 8738/C3DX | Windows XP 2004
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 24th Jan 2004 04:19
imho Option explicit should have been included from day 1. Yes there are fancy ways around the problem of no option explicit, by using types, and this, and that... but why the extra work on our parts? We have enough to contend with already in attempting to code games - no easy task even if the language/ide/debugger were all perfect.

just want it as simple as the first line of code reading:

Option Explicit On

(option strict would be nice too but I won't even go there )

-RUST-
"What the... Mooooooooooo!"
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 24th Jan 2004 23:45
Raven, so it could well be just my interpretation of what the memory usage is. I am aware of most of the memory management functions under the Windows Kernel but the obvious (Chewing) of memory when running me program is worrying if I can't trace where the leak is occurring.

I did sort out the labelling and varariable assignment, took me an hour or so to sift through the code checking every single function and found a couple of potential smackers, but the memory usage is still there. I'm stumpped as to where it's getting used.

I stuck SECTION_analysis functions on all include modules that used arrays and they all contained legitimate count values depending on their usage, yet this 32k paging problem just chewed up the memory every couple of seconds. I've not left the program running long enough to see exactly what happens when the memory usage hits maximum, probably throw up (Low resources) error or something and completely splat the OS or max out the swap file but I need to test this incase it is just a rougue memory usage value being displayed.

The last thing I need is to release my program onto the Internet community, only to find that it chews up their memory and swap file space!! lol. Best put a clause or disclaimer in there I think.

Anyway, back to my last posting. Labels should definately be localised to the function scope (Although the editor could actually check this before compiling, depending on which IDE is in use) And an Option explicit, again could be checked by the editor if it handled the DB syntax correctly.

And, ON ERROR, now I agree that this is a BASIC concept, so exception handling (Try, Catch and Throw) is probably too advanced for the scope of DarkBASIC as an error handling system and this would need some form of exception object handling that Cattle pointed out. But ON ERROR is a good start.

Ah yes, this should keep the lot of us discussing potential error handling routines and procedures for a while.

Paul.


Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 25th Jan 2004 13:02
does your code ever actualy run out of memory though??, I wouldn`t trust the values the DB functions return, like Raven says, they often seem to be making up numbers just because they look nice or something ,you could install an external memory usage app and see if DB is realy eating memory, or if it`s just being silly, you could test by modding your code to run its self without user input and see how long it runs before crashing, none of my programs have managed to run out of memory, however long they run (and some have run for days at a time)

Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 2x160Gb HD (using icewave hd coolers ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800Pro 128mb.
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 25th Jan 2004 19:52
Mentor, I'm not sure as yet because of a bug that is so difficult to trace, hence my original query. I'm still trying to trace whether it's a string mansgement problem becuase I reach a certain point in my program, then it dies. I'm getting there but it's a nightmare!!

Paul.


zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 25th Jan 2004 20:01
Please keep working on this, code stability is always an important thing when you want to release a program. I'd like to see this mystery solved.
--
TAZ

APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 14:21 Edited at: 27th Jan 2004 14:21
With regard to memory leaks or potential problems, take a look at this function.



This is a killer when it comes to performance, and after so many calls, it makes my program die!

Does anybody have an alternative to trimming the outer speech marks of a string that is !FAST!. It could be done in C as an external DLL call but was hoping that someone has already done this with a set of string handling routines.

Interesting problem though.


OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 27th Jan 2004 14:25
How many calls do you make to this function - any example code ?


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 14:29
I'll dogwatch it and tell you exactly how many times before it splats.

BRB


APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 14:44
TCA,

Note that the test was done by incrementing an integer and throwing it out to a file for inspection when program dies.

First attempt, the function was called 204 times

Second attempt, the function was called 185 times

Now if I rem out the call and ensure that the string being processed does not contain an outer set of quotes, my program runs as as smooth as a babies bottom. This function is definately causing a serious problem for me.

Paul.


OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 27th Jan 2004 15:36
Memory does jump around a bit - however, at the moment I dont know whether its cause by the other running programs. I could only notice a different running 10,000 iterations.


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 27th Jan 2004 15:53
It seems to be inconclusive - memory increases and decreases all the time. However, I do know that CPU processing is at 100%, and the page file usage history increased slightly.




The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 16:43
TCA, the thing that also may change the statistics is that the value I pass in is comming directly from a user defined typed array.

What I'll do is I'll modify your example, (I don't wish to post my code as this is a fairly tightlipped project), but use the same calling convention and routing that's applied through my project and see if there is any difference.

Paul.


APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 18:19
TCA,

Right, I've stripped out as much as I can without serious alteration to the code, the sections that I use that are a primary calling point for the TrimQuotes function. There are other sections of my project that use it but this bit is used very frequently and is a good starting point to see where not only the drop in performance but also watch the memory usage slowly go up.

Download http://www.apexnow.co.uk/cs/stringtest.zip

It uses exclusive mode and there's a constant called _USE_TRIMMER

Set it to 1 to use the TrimQuotes function and zero to ignore it.

Try to see if you can discover where the slow increase in memory is occurring and whether it is anything to do with the TrimQuotes function.

Like I said in my other post, this performance drop dissapears when the TrimQuotes function is removed.

Many thanks for your assistance mate

Paul


OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 27th Jan 2004 19:29 Edited at: 27th Jan 2004 20:28
The memory usage is up & down like a yo-yo both with and without _SET_TRIMMER

I had thought it was calls to functions/subroutines, but it appears not, which leaves either the TEXT or SYNC functions, or possibly the WHILE commands. Alternatively, parts of the program have to be shifted out into the swap file (hence the use of the hard drive).

As memory usage goes up & down on my XP machine (doesn't seem to be a fixed pattern to it at all), I suspect its due to a fairly inefficient memory system (although its better than 98) - the OS is claiming memory (for whatever reason), and of course cant/wont release it when its been finished.

Seems that Raven and I are in agreement with this.

Are you using 98 by any chance ?

As for what you can do a lot about it - unless Lee has forgotten to pull registers off the stack with some commands, I doubt there is much you can do about it... Perhaps IanM may have a few extra ideas.


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Jan 2004 20:07
Whether this is a problem with DBPro, or memory management isn't clear to me, but I tried a few things myself ...

I tried to reduce the number of temporary strings generated by the compiler ...



This only generates temporaries for the 'chr$(34)' pieces. The apparent memory usage slowed.

Using this piece of code slowed memory usage even further, but didn't stop it.



Both pieces of code need my utility plug-in.

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 20:21
I could only pin down the problem to some form of allocation/deallocation of strings but like you, I couldn't see exactly where it was occurring. My development machine is Win2K Prof (SP4).

I'll experiment with the examples Ian has given to see if this also adds improvement to the performance of the function. It's most odd though.

TCA, the problem with the example I've given is that the function is only called inside the main loop from the CACHE_Find and CACHE_Add functions. But from my main project's point of view, this occurs as the script parser thumbles down through the OP codes, allocating variables n such. It's a pretty heavy peice of code, especially for DBPro but so far, it works really well. (Except for the string bit LOL)

Thanks for the input guys.

Paul.


OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 27th Jan 2004 20:30
I think any claimed memory would be put back into the free pool at some point, so you shouldn't actually run out of memory.

Perhaps Lee may be able to shed some light on the problem.


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
APEXnow
Retired Moderator
22
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jan 2004 20:34
I know Lee's busy with the FPSC but I'll post this on DBDN and see if he can shed a small pin prick of light onto the matter. Cheers TCA, IanM

Paul.


Login to post a reply

Server time is: 2025-05-28 03:09:17
Your offset time is: 2025-05-28 03:09:17