473,943 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Releasing the resource retrieved by Assembly.GetMan ifestResourceSt ream()

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.GetMan ifestResourceSt ream() 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.__Unm anagedMemoryStr eam returned by
GetManifestReso urceStream() 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.__Unm anagedMemoryStr eam? Perhaps I am not
using Assembly.GetMan ifestResourceSt ream() as it is intended.

Any ideas or suggestions are appreciated!
Sample Program:

// Wrapper for Assembly.GetMan ifestResourceSt ream().
class ResourceReader {

public ResourceReader( string strResourceFile ) {
cstrResourceFil e = strResourceFile ;
}

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

try {
oResourceStream =
Assembly.GetExe cutingAssembly( ).GetManifestRe sourceStream(
cstrResourceFil e );
oReader = new StreamReader( oResourceStream );
return oReader.ReadToE nd();
}
catch( Exception ) {
return String.Empty;
}
finally {
if( oResourceStream != null ) {
oResourceStream .Flush();
oResourceStream .Close();
}

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

private string cstrResourceFil e;
}

// Program entry point.
class TestHarness {

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

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

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

++n;
}
}
}

Sincerely,
Steve Guidi

Nov 22 '05 #1
0 1662

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

Similar topics

0
508
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 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
5
8259
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 of type 'System.ArgumentException' occurred in system.drawing.dll Additional information: 'null' is not a valid value for 'stream'.
3
1588
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 = assembly.GetCallingAssembly.GetManifestResourceStream("ResourceName");
12
2084
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 Embedded Resource... Now where should look next... Any help...
1
3621
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 _ System.IO.StreamReader(Me.GetType.Assembly.GetManifestResourceStream("myname space.script.js")) I receive the error: Value cannot be null. Parameter name: stream I think the underlying problem is that the name of the assembly
11
5599
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 set to Embedded Resource. I've searched high and low for the code that will actually make it load as the program's default icon, but nothing I've found works. Can someone give me the code necessary to do this?
6
2694
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 can I retrieve its content in the runtime? Any help is deeply appreciated. Thanks you very much in advance. Kate
0
1109
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^ resource; System::Void Button_Click(System::Object^ sender, System::EventArgs^ e) { resource = Assembly::GetManifestResourceStream("Fido.jpg");
3
10651
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 Windows, and they play fine outside of my app. This code works, but has the random "scratching" problem: private static void PlayResource(string audioRes) { // Get the resource into a stream
4
3437
by: Peter Larsen [] | last post by:
Hi, How do i read a resource string from a dll in code ?? BR Peter
0
10138
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11133
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11301
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10666
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9866
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4515
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.