Click here to Skip to main content
15,922,584 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to "copy local dependencies" in C# !? Pin
J a a n s24-Jul-08 4:45
professionalJ a a n s24-Jul-08 4:45 
QuestionStruct / Class strange problem Pin
lune1224-Jul-08 4:16
lune1224-Jul-08 4:16 
AnswerRe: Struct / Class strange problem Pin
leppie24-Jul-08 4:31
leppie24-Jul-08 4:31 
AnswerRe: Struct / Class strange problem Pin
User 665824-Jul-08 6:56
User 665824-Jul-08 6:56 
AnswerRe: Struct / Class strange problem Pin
Guffa24-Jul-08 11:10
Guffa24-Jul-08 11:10 
GeneralRe: Struct / Class strange problem Pin
lune1227-Jul-08 21:00
lune1227-Jul-08 21:00 
QuestionKilling a byte array? Pin
Justin Time24-Jul-08 4:06
Justin Time24-Jul-08 4:06 
AnswerRe: Killing a byte array? Pin
Luc Pattyn24-Jul-08 4:33
sitebuilderLuc Pattyn24-Jul-08 4:33 
Hi,

your code contains a lot of unnecessary stuff, e.g. there is no reason whatsoever
to clear the array you are no longer interested in. If byteData is the only reference
to the array, it will be collectable as soon as byteData either goes out of scope,
or is modified (e.g. set to null). The array content does not matter in this.

But collectable does not mean collected; the Garbage Collector will collect only
when it feels a need to do so, which typically means something else is being created,
needing some memory, and the GC decides it would be either necessary or desirable
to go look for freeing some memory first.

For regular objects, the GC moves them together to avoid wasting memory holes
(fragmentation). So debug tools will pretty soon be unable to read the old data,
since it gets overwritten by the data of the new object that caused the GC to
kick in in the first place.

Now large objects are treated differently; there is a special "large object heap",
where objects never get moved around to keep free memory logically contiguous, mainly
because it is too expensive to move them. IIRC the threshold once was around 80KB.

So even when a large object gets collected, as long as a new large object is not
overwriting the old one, your debug tools will be able to see the old content in memory.
A terrible drawback of all this is when your large objects require an ever growing
size, the holes never get reused, fragmentation kicks in, and you eventually run
out of memory, although most of the large object heap may be free!

If this is not acceptable (your app needs to run for long times) and/or if your
problems persist, I would recommend you try and avoid those large objects altogether,
e.g.:
- why store multiple images in a single huge file? consider using one file per image,
and one file with filenames.
- why convert a very large image to a single base64 string? consider using several
smaller base64 strings.
etc.

Of course, dealing with the above will require more code, but in the end it
will be worth it and perform much better.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Voting for dummies? No thanks. Dead | X|


GeneralRe: Killing a byte array? Pin
Justin Time24-Jul-08 4:48
Justin Time24-Jul-08 4:48 
GeneralRe: Killing a byte array? Pin
Luc Pattyn24-Jul-08 5:02
sitebuilderLuc Pattyn24-Jul-08 5:02 
GeneralRe: Killing a byte array? Pin
Justin Time24-Jul-08 6:07
Justin Time24-Jul-08 6:07 
GeneralRe: Killing a byte array? Pin
Luc Pattyn24-Jul-08 7:27
sitebuilderLuc Pattyn24-Jul-08 7:27 
GeneralRe: Killing a byte array? Pin
Justin Time24-Jul-08 8:14
Justin Time24-Jul-08 8:14 
GeneralRe: Killing a byte array? Pin
Luc Pattyn24-Jul-08 9:06
sitebuilderLuc Pattyn24-Jul-08 9:06 
GeneralRe: Killing a byte array? [modified] Pin
DaveyM6924-Jul-08 23:07
professionalDaveyM6924-Jul-08 23:07 
GeneralRe: Killing a byte array? Pin
Luc Pattyn25-Jul-08 3:44
sitebuilderLuc Pattyn25-Jul-08 3:44 
GeneralRe: Killing a byte array? Pin
Luc Pattyn24-Jul-08 9:28
sitebuilderLuc Pattyn24-Jul-08 9:28 
AnswerRe: Killing a byte array? Pin
leppie24-Jul-08 4:33
leppie24-Jul-08 4:33 
GeneralRe: Killing a byte array? Pin
Justin Time24-Jul-08 4:43
Justin Time24-Jul-08 4:43 
QuestionDisable Browser Pin
Agweet24-Jul-08 3:35
Agweet24-Jul-08 3:35 
AnswerRe: Disable Browser Pin
Pete O'Hanlon24-Jul-08 4:00
mvePete O'Hanlon24-Jul-08 4:00 
GeneralRe: Disable Browser Pin
Agweet24-Jul-08 20:22
Agweet24-Jul-08 20:22 
AnswerRe: Disable Browser Pin
PIEBALDconsult24-Jul-08 6:23
mvePIEBALDconsult24-Jul-08 6:23 
Questionip address Pin
AlexPizzano24-Jul-08 2:16
AlexPizzano24-Jul-08 2:16 
AnswerRe: ip address Pin
teejayem24-Jul-08 2:27
teejayem24-Jul-08 2:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.