Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Proper use of the .New methods, out of memory error


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2008, 04:17 AM
Junior Member
 
Join Date: Sep 2007
Posts: 28
Default Proper use of the .New methods, out of memory error

Hello all,

I have a program that uses a few bitmap objects. I see that the program keeps on allocating memory as it runs. When I change the bitmaps I call the New methods again.

So the question is do the new methods allocate new object memory each time or does it just reinitialize the object and it's memory. I've been under the impression that it just reinitializes the object. Should I be just changing the .value method and avoid calling New over and over. This goes for all objects actually.

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-05-2008, 06:27 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,132
Default

The .Net garbage collector should free unused memory.
Do you get an out of memory exception?
It is possible that the bitmaps are still referenced somewhere in your program and therefore their resources will not be freed.
In that case it is better to use Value instead of New which creates a new object.

You could also manually dispose the object before creating a new one:
Code:
Bitmap1.Dispose
AddObject("Bitmap1","Bitmap")
Bitmap1.New1(...)
Reply With Quote
  #3 (permalink)  
Old 09-05-2008, 02:10 PM
Junior Member
 
Join Date: Sep 2007
Posts: 28
Default

Hi Erel,

Yes eventually I get a out of memory exception. I can see that the memory allocated by the program steadily increases. The gccollect method helps but the allocated memory still increases.

I have three bitmaps objects that I continually use in the program. The bitmap continually get changed. At the moment I call new each time I need to change the bitmaps. The bitmap is "on" the screen when new is called. I don't create any additional bitmap objects just reuse the three I already have.

So, if I follow, because the bitmaps are being used/referenced in the program a dispose and addobject is needed to free all memory.

Is this advice for all other objects as well?

Thanks
Reply With Quote
  #4 (permalink)  
Old 09-05-2008, 02:20 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,132
Default

GCCollect should not be used. The garbage collector will free unused memory from time to time or when free memory drops below a certain value.

Did you try to assign the Value property instead of calling New?
Reply With Quote
  #5 (permalink)  
Old 09-05-2008, 02:33 PM
Junior Member
 
Join Date: Sep 2007
Posts: 28
Default

In some places I load the image from a file. To use the value method it seems to me that I need to then make a imagelist but I don't particularly care to do this because the images are background images and can be many. I can try just to see the result.
Reply With Quote
  #6 (permalink)  
Old 09-05-2008, 02:37 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,132
Default

The Dispose / AddObject is a good solution.
Quote:
Is this advice for all other objects as well?
You should not use it with most objects that unless you repeatedly create and destroy such objects.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
DateTime compatibility methods berndgoedecke Basic4ppc Wishlist 4 08-31-2008 06:43 PM
Build proper desktop apps in B4PPC with this awesome Forms library agraham Additional Libraries 25 07-30-2008 05:19 PM
Out of Memory Exception Error on Load willisgt Questions & Help Needed 9 03-01-2008 12:18 PM
out-of-memory-error based on timer after switching to V6 Frank Questions & Help Needed 2 01-17-2008 04:26 PM
Out of Memory error while loading bitmap HARRY Questions & Help Needed 3 05-15-2007 01:12 PM


All times are GMT. The time now is 12:29 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0