Memory leak with a memory streamWhat strategies and tools are useful for finding memory leaks in .NET?Creating a byte array from a streamHow do I copy the contents of one stream to another?Is a memory leak created if a MemoryStream in .NET is not closed?How do I save a stream to a file in C#?Memory Leak in C#How to convert an Stream into a byte[] in C#?Displaying live video from a raw uncompressed byte source in C#: WPF vs. Win formsHow do I generate a stream from a string?Why and How to avoid Event Handler memory leaks?
Why airport relocation isn't done gradually?
Extreme, but not acceptable situation and I can't start the work tomorrow morning
Why is my log file so massive? 22gb. I am running log backups
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Is this food a bread or a loaf?
Landing in very high winds
Are objects structures and/or vice versa?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Lied on resume at previous job
How to manage monthly salary
Doomsday-clock for my fantasy planet
"listening to me about as much as you're listening to this pole here"
Is a vector space a subspace of itself?
Is Social Media Science Fiction?
What does 'script /dev/null' do?
Where to refill my bottle in India?
What causes the sudden spool-up sound from an F-16 when enabling afterburner?
Information to fellow intern about hiring?
LWC and complex parameters
How to deal with fear of taking dependencies
Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?
What do the Banks children have against barley water?
Why is the design of haulage companies so “special”?
Map list to bin numbers
Memory leak with a memory stream
What strategies and tools are useful for finding memory leaks in .NET?Creating a byte array from a streamHow do I copy the contents of one stream to another?Is a memory leak created if a MemoryStream in .NET is not closed?How do I save a stream to a file in C#?Memory Leak in C#How to convert an Stream into a byte[] in C#?Displaying live video from a raw uncompressed byte source in C#: WPF vs. Win formsHow do I generate a stream from a string?Why and How to avoid Event Handler memory leaks?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I know this code is far from perfect but in my case this was the only
way to do it correctly because im embedding WPF in C#, and when
applying text regulary the Spellcheck does not work correctly
So this is my code:
RichTextBox temphotfix = new RichTextBox();
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
MemoryStream stream = new MemoryStream(byteArray);
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
temphotfix.Dispose();
stream.Dispose();
I stress tested this, and it seems like ever about 5 times the script gets ran, it adds about 1 MB ram.
What am i doing wrong, i litterly made everyting i used null, or desposed them.
c#
add a comment |
I know this code is far from perfect but in my case this was the only
way to do it correctly because im embedding WPF in C#, and when
applying text regulary the Spellcheck does not work correctly
So this is my code:
RichTextBox temphotfix = new RichTextBox();
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
MemoryStream stream = new MemoryStream(byteArray);
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
temphotfix.Dispose();
stream.Dispose();
I stress tested this, and it seems like ever about 5 times the script gets ran, it adds about 1 MB ram.
What am i doing wrong, i litterly made everyting i used null, or desposed them.
c#
4
Garbage Collection isn't going to happen when you set things tonull
or callDispose
. It runs when it deems the memory pressure requires it.
– juharr
Mar 22 at 2:18
1
The good news is that with 4GB free RAM, you can afford run this about 20,000 times before running out of memory. So see what happens when you run it 1,000,000 times - and if you run out of memory then, you've got a problem.
– MineR
Mar 22 at 2:59
2
you can useUsing
block to decorate theMemoryStream
or as well onRichTextBox
that will help this object gets deallocated as soon as it comes out of scope, instead of callingDispose
.
– Abhinaw Kaushik
Mar 22 at 4:11
4
Use a memory profiler to diagnose memory problems.
– Eric Lippert
Mar 22 at 5:27
Youd did not stress test this. That would have ended with an OOM exception or (more likely) with an Ok.
– Henk Holterman
Mar 23 at 20:26
add a comment |
I know this code is far from perfect but in my case this was the only
way to do it correctly because im embedding WPF in C#, and when
applying text regulary the Spellcheck does not work correctly
So this is my code:
RichTextBox temphotfix = new RichTextBox();
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
MemoryStream stream = new MemoryStream(byteArray);
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
temphotfix.Dispose();
stream.Dispose();
I stress tested this, and it seems like ever about 5 times the script gets ran, it adds about 1 MB ram.
What am i doing wrong, i litterly made everyting i used null, or desposed them.
c#
I know this code is far from perfect but in my case this was the only
way to do it correctly because im embedding WPF in C#, and when
applying text regulary the Spellcheck does not work correctly
So this is my code:
RichTextBox temphotfix = new RichTextBox();
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
MemoryStream stream = new MemoryStream(byteArray);
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
temphotfix.Dispose();
stream.Dispose();
I stress tested this, and it seems like ever about 5 times the script gets ran, it adds about 1 MB ram.
What am i doing wrong, i litterly made everyting i used null, or desposed them.
c#
c#
edited Mar 22 at 5:35
Uwe Keim
27.7k32134216
27.7k32134216
asked Mar 22 at 1:54
Mika SDMika SD
12
12
4
Garbage Collection isn't going to happen when you set things tonull
or callDispose
. It runs when it deems the memory pressure requires it.
– juharr
Mar 22 at 2:18
1
The good news is that with 4GB free RAM, you can afford run this about 20,000 times before running out of memory. So see what happens when you run it 1,000,000 times - and if you run out of memory then, you've got a problem.
– MineR
Mar 22 at 2:59
2
you can useUsing
block to decorate theMemoryStream
or as well onRichTextBox
that will help this object gets deallocated as soon as it comes out of scope, instead of callingDispose
.
– Abhinaw Kaushik
Mar 22 at 4:11
4
Use a memory profiler to diagnose memory problems.
– Eric Lippert
Mar 22 at 5:27
Youd did not stress test this. That would have ended with an OOM exception or (more likely) with an Ok.
– Henk Holterman
Mar 23 at 20:26
add a comment |
4
Garbage Collection isn't going to happen when you set things tonull
or callDispose
. It runs when it deems the memory pressure requires it.
– juharr
Mar 22 at 2:18
1
The good news is that with 4GB free RAM, you can afford run this about 20,000 times before running out of memory. So see what happens when you run it 1,000,000 times - and if you run out of memory then, you've got a problem.
– MineR
Mar 22 at 2:59
2
you can useUsing
block to decorate theMemoryStream
or as well onRichTextBox
that will help this object gets deallocated as soon as it comes out of scope, instead of callingDispose
.
– Abhinaw Kaushik
Mar 22 at 4:11
4
Use a memory profiler to diagnose memory problems.
– Eric Lippert
Mar 22 at 5:27
Youd did not stress test this. That would have ended with an OOM exception or (more likely) with an Ok.
– Henk Holterman
Mar 23 at 20:26
4
4
Garbage Collection isn't going to happen when you set things to
null
or call Dispose
. It runs when it deems the memory pressure requires it.– juharr
Mar 22 at 2:18
Garbage Collection isn't going to happen when you set things to
null
or call Dispose
. It runs when it deems the memory pressure requires it.– juharr
Mar 22 at 2:18
1
1
The good news is that with 4GB free RAM, you can afford run this about 20,000 times before running out of memory. So see what happens when you run it 1,000,000 times - and if you run out of memory then, you've got a problem.
– MineR
Mar 22 at 2:59
The good news is that with 4GB free RAM, you can afford run this about 20,000 times before running out of memory. So see what happens when you run it 1,000,000 times - and if you run out of memory then, you've got a problem.
– MineR
Mar 22 at 2:59
2
2
you can use
Using
block to decorate the MemoryStream
or as well on RichTextBox
that will help this object gets deallocated as soon as it comes out of scope, instead of calling Dispose
.– Abhinaw Kaushik
Mar 22 at 4:11
you can use
Using
block to decorate the MemoryStream
or as well on RichTextBox
that will help this object gets deallocated as soon as it comes out of scope, instead of calling Dispose
.– Abhinaw Kaushik
Mar 22 at 4:11
4
4
Use a memory profiler to diagnose memory problems.
– Eric Lippert
Mar 22 at 5:27
Use a memory profiler to diagnose memory problems.
– Eric Lippert
Mar 22 at 5:27
Youd did not stress test this. That would have ended with an OOM exception or (more likely) with an Ok.
– Henk Holterman
Mar 23 at 20:26
Youd did not stress test this. That would have ended with an OOM exception or (more likely) with an Ok.
– Henk Holterman
Mar 23 at 20:26
add a comment |
1 Answer
1
active
oldest
votes
As I told above in comment you can using
, you can try this code. hope this should help.
using (RichTextBox temphotfix = new RichTextBox())
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
using (MemoryStream stream = new MemoryStream(byteArray))
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
//temphotfix.Dispose();
//stream.Dispose();
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291781%2fmemory-leak-with-a-memory-stream%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As I told above in comment you can using
, you can try this code. hope this should help.
using (RichTextBox temphotfix = new RichTextBox())
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
using (MemoryStream stream = new MemoryStream(byteArray))
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
//temphotfix.Dispose();
//stream.Dispose();
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
add a comment |
As I told above in comment you can using
, you can try this code. hope this should help.
using (RichTextBox temphotfix = new RichTextBox())
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
using (MemoryStream stream = new MemoryStream(byteArray))
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
//temphotfix.Dispose();
//stream.Dispose();
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
add a comment |
As I told above in comment you can using
, you can try this code. hope this should help.
using (RichTextBox temphotfix = new RichTextBox())
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
using (MemoryStream stream = new MemoryStream(byteArray))
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
//temphotfix.Dispose();
//stream.Dispose();
As I told above in comment you can using
, you can try this code. hope this should help.
using (RichTextBox temphotfix = new RichTextBox())
temphotfix.Font = new Font(temphotfix.Font.Name, 14);
System.Windows.Documents.TextRange range = new System.Windows.Documents.TextRange(omschrijving.Document.ContentStart, omschrijving.Document.ContentEnd);
temphotfix.Text = oms;
string temp = temphotfix.Rtf;
byte[] byteArray = Encoding.ASCII.GetBytes(temp);
using (MemoryStream stream = new MemoryStream(byteArray))
range.Load(stream, DataFormats.Rtf);
range = null;
temp = null;
byteArray = null;
//temphotfix.Dispose();
//stream.Dispose();
answered Mar 22 at 4:22
Abhinaw KaushikAbhinaw Kaushik
370212
370212
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
add a comment |
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
I did not fix it, but i tink it does help a little bit.
– Mika SD
Mar 22 at 21:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291781%2fmemory-leak-with-a-memory-stream%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Garbage Collection isn't going to happen when you set things to
null
or callDispose
. It runs when it deems the memory pressure requires it.– juharr
Mar 22 at 2:18
1
The good news is that with 4GB free RAM, you can afford run this about 20,000 times before running out of memory. So see what happens when you run it 1,000,000 times - and if you run out of memory then, you've got a problem.
– MineR
Mar 22 at 2:59
2
you can use
Using
block to decorate theMemoryStream
or as well onRichTextBox
that will help this object gets deallocated as soon as it comes out of scope, instead of callingDispose
.– Abhinaw Kaushik
Mar 22 at 4:11
4
Use a memory profiler to diagnose memory problems.
– Eric Lippert
Mar 22 at 5:27
Youd did not stress test this. That would have ended with an OOM exception or (more likely) with an Ok.
– Henk Holterman
Mar 23 at 20:26