473,383 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Releasing the resource retrieved by Assembly.GetManifestResourceStream()

Hello,

I'm developing an application that periodically reads embedded assembly
resources. The resources are text-based, and are about 3-7KB in size,
and the application accesses them by calling the
Assembly.GetManifestResourceStream() method.

During a long period of execution, I've noticed that the memory usage
of the application increases; specifically, it appears that the
System.IO.__UnmanagedMemoryStream returned by
GetManifestResourceStream() is never collected, even when the owning
thread leaves the scope in which it is defined.

I used SciTech's memory profiler to track down this issue and was able
to reproduce it with the appended code.

Does someone know if there is a way to force the release of the
resources used by System.IO.__UnmanagedMemoryStream? Perhaps I am not
using Assembly.GetManifestResourceStream() as it is intended.

Any ideas or suggestions are appreciated!
Sample Program:

// Wrapper for Assembly.GetManifestResourceStream().
class ResourceReader {

public ResourceReader( string strResourceFile ) {
cstrResourceFile = strResourceFile;
}

public string GetText() {
Stream oResourceStream = null;
TextReader oReader = null;

try {
oResourceStream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream(
cstrResourceFile );
oReader = new StreamReader( oResourceStream );
return oReader.ReadToEnd();
}
catch( Exception ) {
return String.Empty;
}
finally {
if( oResourceStream != null ) {
oResourceStream.Flush();
oResourceStream.Close();
}

if( oReader != null ) {
oReader.Close();
}
}
}

private string cstrResourceFile;
}

// Program entry point.
class TestHarness {

static void Main(string[] args) {
string data = null;
ResourceReader oReader = new ResourceReader(
"ConsoleApplication1.TextFile1.txt" );
int n = 0;

while( true ) {
data = oReader.GetText();
System.Threading.Thread.Sleep( 3000 );

if( n % 250 == 0 ) {
System.GC.Collect();
}

++n;
}
}
}

Sincerely,
Steve Guidi

Nov 22 '05 #1
0 1618

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve Guidi | last post by:
Hello, I'm developing an application that periodically reads embedded assembly resources. The resources are text-based, and are about 3-7KB in size, and the application accesses them by calling...
5
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception...
3
by: John | last post by:
Hi, I have a base class that's compiled in an assembly. public class mybase { public void mymethod() { //can i get the embeded resources? //Stream st =...
12
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
1
by: Brad | last post by:
I'm having a problem reading a resource stream using the following syntax: Dim resStream As System.IO.TextReader = New _ ...
11
by: Garrett | last post by:
I'm fairly new to VB .NET and programming in general, and I want to give my program its own icon without it being a separate file. I have the icon as part of the project, and its Build Action is...
6
by: cql90 | last post by:
Hi All, I have created a folder call Resource within my project, I have added a XML file into the resource folder, and I set the BuildAction property of the XML file to "Embedded Resource". How...
0
by: poojo hackma | last post by:
How can I load a System Resource image into a PictureBox with the CLR? Code: //----------------------------------------- System::Windows::Forms::PictureBox^ PictureBox1; System::IO::Stream^...
3
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with...
4
by: Peter Larsen [] | last post by:
Hi, How do i read a resource string from a dll in code ?? BR Peter
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.