NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 82 83 84 85 86 … 93 Next »
memory issues and images

 
  • 0 Vote(s) - 0 Average
memory issues and images
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#1
2004-12-09, 01:45 AM
im still at uni, so forgive me if this is a silly question, i have an arraylist of a class i created, in this class there are a few images assoicated with it.
this arraylist changes each time a user changes a directory. and i simple use
currentDirectory = new FileDetails() (the arraylist).

should i before calling that, dispose every single image with image.dispose() or would a ~FileDetails() method be called and i could dispose the images in there, or would this make no difference in the memory and just leave it as it is?
KingArgyle
Offline

Posting Freak

Posts: 1,271
Threads: 95
Joined: Nov 2004
#2
2004-12-09, 03:22 AM
Personally, If you are going to be recreating the Arraylist, I like to explicitly clear the ArrayList that was created. You can pretty much accomplish this one of several ways:

1. Iterate through the ArrayList and call the Remove() method for each item.

2. Assign the Arraylist to NULL, and then create a new ArrayList and reload it.

Personally, I like option 1. For speed though, espically with long lists, you may want to look at implementing a Hash Table. Take a look at the following article for some examples:

http://www.thescarms.com/dotNet/Collections.asp

Typically the Garbage Collector should be intelligent enough to detect when an object isn't be actively used any more, however, it never hurts to be sure, by removing the items from the arraylist explicitly. May take a bit more coding on your end, but the GC may clean up after itself sooner.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#3
2004-12-09, 03:39 AM
i was also doing arralist.clear()
arraylist = null;
arraylist = new arraylist();
just forgot to add those two lines.
but since its items in the arraylist, which are all in memory images, would doing this free up that used memory, or would i need to call manually set those images to image.dispose() image= null ?
its just if i have to do that, i would have to iterate through the image list which may take longer (come to think of it, going thru an average directory shouldnt take long, 1000 images in one dir i would consider very large, and probably the peek, doing a loop of 1000 shouldnt take long at all. you think i should do it that way? just trying to clean up the code, and remove overflow exceptions.
thanks KingArgyle youve been helping me out quite a bit.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#4
2004-12-09, 04:08 AM
ok im disposing the arraylist like this
first method called
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
if(arraylist!= null){
arraylist.Dispose();
}
arraylist= null;
[/QUOTE]
this arraylist.dipose method
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
for(int i=this.Count-1;i>=0;i--)
{
((FileDetails)this[i]).Dispose();
this.RemoveAt(i);
}
this.Capacity = 1;
[/QUOTE]
the filedetails.dispose method
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
if(thumbnail[0] != null)
thumbnail[0].Dispose();
thumbnail[0] = null;
if(thumbnail[1] != null)
thumbnail[1].Dispose();
thumbnail[1] = null;
if(thumbnail[2] != null)
thumbnail[2].Dispose();
thumbnail[2] = null;
if(thumbnail[3] != null)
thumbnail[3].Dispose();
thumbnail[3] = null;
[/QUOTE]
thumbnail is an image array, which contains the thumbnail for each different view, these are loaded in the paint method if they are null (so only when needed).
is there anything more i could do?



KingArgyle
Offline

Posting Freak

Posts: 1,271
Threads: 95
Joined: Nov 2004
#5
2004-12-09, 04:51 AM
As far as i know that is all you can do. One of the things I have learned over the years is that even though the computer or language you are using is SUPPOSED to handle stuff for you, that it is still better to tell it what to do instead of letting it figure it out on its own. GC is usually one of those areas where I've found it advantagous to give some helpful nudges to the machine.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#6
2004-12-09, 05:50 AM
thanks man, yeah we never really cover this stuff at uni, they say with C# it covers it for you, C++ isnt really taught anymore, only in a few subjects. javas taught for the first two years, and eh i hate java.

hopefully there shouldnt be anymore buffer over run exception, but when dealing with images, thats never certain.
jasonf
Offline

Member

Posts: 121
Threads: 7
Joined: Oct 2004
#7
2004-12-09, 12:40 PM
Something else to keep in mind is that .NET for whatever reason has problems disposing of objects once they are paged to virtual memory. Sure, GC releases the links to those objects from physical memory, but I've seen my pagefile grow until it filled the machine, despite using any available Dispose() methods.

The problem is related to the fact that GC apparently doesn't load the object back into physical memory when it does it's thing (and why would it? That's the OS's responsibility). And for whatever reason, once the link is broken, that virtual memory is never reclaimed, so it fills with garbage.

The only definitive cure that I've found for this is to increase physical memory on the box so that less objects get paged out into virtual memory and also try to narrow the use of large objects to procedure scope, if possible (the problem for me definitely came from long-lived objects, like global collections in a class). Then, when gc.collect() does its thing, the physical memory occupied by those objects on the heap is released.
JasonF
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#8
2004-12-09, 07:57 PM
ive done a few tests, and when running my pictures, gbpvr is only using at max around 10megs more memory, so i think the problem is fixed to the best i can do it. i could just paint the images from file directly, but that would slow it down. so its a speed/memory thing. memory is cheap these days, so 512 should be enough, im on 256 and had no problems. if there are problems list mode wont display any thumbnails so the images will never been initiated.
« Next Oldest | Next Newest »

Users browsing this thread: 2 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Images in lists using a lot of memory cncb 4 4,046 2015-11-12, 12:02 AM
Last Post: sub
  couple of issues with recording.recurring.save method reven 10 4,685 2014-01-03, 11:11 PM
Last Post: reven
  Navigation Issues cncb 4 2,233 2011-08-11, 11:11 PM
Last Post: cncb
  A list of changing images McBainUK 1 1,861 2011-06-21, 04:36 PM
Last Post: sub
  Updating images scb147 11 4,322 2010-07-30, 06:11 PM
Last Post: scb147
  Displaying images ACTCMS 6 2,484 2009-12-29, 12:37 PM
Last Post: ACTCMS
  Retrieving Images from GetRenderList psycik 11 3,724 2008-08-10, 08:33 PM
Last Post: mvallevand
  Controlling fixedAspectRatio images in a skin ACTCMS 2 1,731 2008-03-29, 03:14 AM
Last Post: ACTCMS
  More On Memory Management Ommina 2 1,702 2008-01-09, 06:54 AM
Last Post: Ommina
  Memory management - controls and popups JavaWiz 2 1,940 2008-01-06, 02:48 AM
Last Post: JavaWiz

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode