Discussion:
Removing images from Memory
Mike Stover
2014-10-01 18:13:39 UTC
Permalink
I currently have a small program that is loading about 1 - 5 images into
memory using wx.FileSystem and wx.MemoryFSHandler. I would like to be able
to also remove these image from memory without closing the app and opening
it again. I won't post the full code unless asked for it, but here are the
important snippets.

In the wx.Frame class __init__:
*wx.FileSystem.AddHandler(wx.MemoryFSHandler())*
* self.theMemHandler = wx.MemoryFSHandler()*

In the function loading the images to memory:
*for image in self.image_list:*
* _image = self.process_image(image)*
* new_image = wx.EmptyImage(_image.size[0], _image.size[1])*
* new_image.SetData(_image.convert('RGB').tostring())*
* final_image = wx.BitmapFromImage(new_image)*
* self.theMemHandler.AddFile(image, final_image,
wx.BITMAP_TYPE_BITMAP)*

I do see a way of removing each image from memory by iterating over my
original list again and using *self.theMemHandler.RemoveFile()*, but I
would like to know if there is a better way.

Thanks,
- Mike S.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robin Dunn
2014-10-07 07:00:08 UTC
Permalink
Post by Mike Stover
I currently have a small program that is loading about 1 - 5 images into
memory using wx.FileSystem and wx.MemoryFSHandler. I would like to be
able to also remove these image from memory without closing the app and
opening it again. I won't post the full code unless asked for it, but
here are the important snippets.
*wx.FileSystem.AddHandler(wx.MemoryFSHandler())*
*self.theMemHandler = wx.MemoryFSHandler()*
*
*
*for image in self.image_list:*
*_image = self.process_image(image)*
*new_image = wx.EmptyImage(_image.size[0], _image.size[1])*
*new_image.SetData(_image.convert('RGB').tostring())*
*final_image = wx.BitmapFromImage(new_image)*
*self.theMemHandler.AddFile(image, final_image, wx.BITMAP_TYPE_BITMAP)*
I do see a way of removing each image from memory by iterating over my
original list again and using *self.theMemHandler.RemoveFile()*, but I
would like to know if there is a better way.
Not sure if this is what you are looking for but if you know what
filenames you used when adding them to the MemoryFSHandler you should be
able to use that with RemoveFile to remove just the ones you want.
There isn't any simple way to remove them all. BTW, The AddFile methods
and RemoveFile are staticmethods, so you don't need an instance to use them.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mike Stover
2014-10-07 14:38:22 UTC
Permalink
Thank you Robin,

I was using a few tutorials I had found for using the MemoryFSHandler that
all created an instance of it first. With your information I should be able
to remove / modify some lines of code. As for removing the images from
memory I am keeping a list of the file names as they are being loaded. I
have also added a "remove" function that iterates over the list and removes
each one. The reason is when the next set of images are loaded they may
share names and it caused a few issues.

Thanks again,
- Mike S.
Post by Robin Dunn
Post by Mike Stover
I currently have a small program that is loading about 1 - 5 images into
memory using wx.FileSystem and wx.MemoryFSHandler. I would like to be
able to also remove these image from memory without closing the app and
opening it again. I won't post the full code unless asked for it, but
here are the important snippets.
*wx.FileSystem.AddHandler(wx.MemoryFSHandler())*
*self.theMemHandler = wx.MemoryFSHandler()*
*
*
*for image in self.image_list:*
*_image = self.process_image(image)*
*new_image = wx.EmptyImage(_image.size[0], _image.size[1])*
*new_image.SetData(_image.convert('RGB').tostring())*
*final_image = wx.BitmapFromImage(new_image)*
*self.theMemHandler.AddFile(image, final_image, wx.BITMAP_TYPE_BITMAP)*
I do see a way of removing each image from memory by iterating over my
original list again and using *self.theMemHandler.RemoveFile()*, but I
would like to know if there is a better way.
Not sure if this is what you are looking for but if you know what
filenames you used when adding them to the MemoryFSHandler you should be
able to use that with RemoveFile to remove just the ones you want.
There isn't any simple way to remove them all. BTW, The AddFile methods
and RemoveFile are staticmethods, so you don't need an instance to use them.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...