Windows Service Rant
-
Marc Clifton wrote:
I don't think that would be expected. A local variable would be declared on the stack
Only if they are structs built out of structs. Classes are always allocated on the heap with a reference from the stack.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
Andy Brummer wrote:
Classes are always allocated on the heap with a reference from the stack.
Yeah, I know. I guess when he said "local variable", I was thinking something like
int foo;
, notA foo=new A();
Marc -
Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Check all the .net memory performance counters for the process. If you have a dangling reference then gen 1 and 2 will be growing. If it is just objects which are quickly released then objects should mostly live in gen0. Also if you are allocating large arrays, they can be allocated on the large object heap which has different cleanup behavior. I've allocated roughly 10 100 meg arrays causing the process to use an extra gig. Calling collect after the array went out of scope caused constant memory use, and then an object cache fixed it for final production use.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
Andy Brummer wrote:
Classes are always allocated on the heap with a reference from the stack.
Yeah, I know. I guess when he said "local variable", I was thinking something like
int foo;
, notA foo=new A();
MarcI Did a double take after replying as I didn't see it was you when I answered. Kinda figured you were pretty familiar with the whole .net memory management thing. :laugh:
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
I Did a double take after replying as I didn't see it was you when I answered. Kinda figured you were pretty familiar with the whole .net memory management thing. :laugh:
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
Andy Brummer wrote:
Kinda figured you were pretty familiar with the whole .net memory management thing.
Yeah, after your reply, I figured I better CMA quickly! Marc
-
Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Sounds like you have a good use for a memory profiler... a good one will give you info about held, reachable, and finalized objects as well as a lot of other memory details. I like to use JetBrains dotTrace[^]. * *I'm not associated with JetBrains in any way, just a happy user. Well ok, I did happen to get dotTrace free when I was a Microsoft MVP.
-
You could just null the unused objects and maintain a count of them, and when the count meets a preset limit, call the GC on them.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001They call this "smart pointers". ;P
The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.
-
Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Take a look at using Weak references[^]. It could be that you have something being held that could easily be released, such as an event.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
You want to use less stack space? (OK that is a programming question) Add the following to you app.config (in the Runtime section):
<disableCommitThreadStack enabled="1" />
You might want to call
GC.Collect
occasionally too if you have plenty of spare memory.xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Ennis Ray Lynch, Jr. wrote:
Turns out every time a local variable is declared (even a base value type) the memory usage would go up
BTW, it sounds like you are boxing the valuetype 'instances' (actually values) (which does have it's roles in a very few corners of the CS application space), maybe it is time to explore generics ;P
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
I had a thought - if the objects are too big, they get put on a different heap - one that isn't affected by the garbage collector. Someone else pointed out that you said "local" variable. It might be that the GC won't delete them because it sees them as still in use, so you might want to look into making it global (and maybe static) to the service itself, yet outside the service1 class itself. Maybe also make it disposable.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001