About Me

My photo
Northglenn, Colorado, United States
I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).

Tuesday, January 16, 2007

C# Leaking

I got this info from MSDN magazine Jan 2007 Vol 22 No 1 issue.

Leaking Unmanaged Heap Memory:

  • Interoperating with unmanaged code



  • Problem: "Using C-style DLLS that use P/Invoke and COM objects through COM interop. The Garbage Collector is unaware of unmanaged memory".


    Solution: "Step through the code and examine memory usage before and after the unmanaged call to verify that the memory is reclaimed."


  • Aborted Finalizers



  • Problem: "An objects finalizer does not get called and it contains code to clean up unmanaged memory allocated by the object".


    Solution: "In .Net 1.x the only solution was to tear down the process and start again. The .Net Framework 2.0 introduces critical finalizers, which indicate that a finalizer will be cleaning up unmanaged resources and must be given a chance to run during AppDomain teardown."


  • Dynamic Code Generation Leaks



  • Problem: "Sometimes code needs to be generated dynamically... dynamic assemly must be regenerated. The old assembly will no longer be used, but there is no way to evict it from memory."
    Solution: "Check if you are regenerat[ing] code". You could either "load the generated MSIL into a child AppDomain. The child AppDomain can be unloaded when the generated code changes and a new one spun up to host the updated MSIL." Or, in 2.0 you can use DynamicMethod.Invoke.

  • XmlSerializer Leaks



  • Problem: "XMLSerializer caches the temporary assemblies on a per-type basis" and when changing the root name within the XML by overloading the XMLSerializer constructor which doesn't cache.


    Solution: Use XMLRootAttribute instead.



Leaking Managed Heap Memory

  • Large Obect Heap Fragmentation



  • Problem: An object is 85,000 bytes or larger and allocated on the large object heap. "Unlike the rest of the managed heap, the Large Obect Heap is not compacted due to the cost of moving the large object. So as large objects are allocated, freed and cleanded up, gaps will appear." Which result in more memory usage then needed.


    Solution: Try examining "how the application uses memory and specifically the types of objects that are on the large object heap using tools like CLRProfiler". Try to reduce the reliance on the LOH.


  • Unneeded Rooted References



  • Problem/Solution: Forgetting to Null out rooted references, which prevents the GC from freeing up memory.


  • Midlife Crisis



  • Problem: "A midlife crisis [...] is the overuse of managed heap memory and excessive amounts of processor time spent in the GC". An object lives to Gen1 or Gen2 and dies shortly afterward.


    Solution: Beware of using finalizers in managed code. Use finalizers if there is a reference to unmanaged code. If using IDisposable, "implement the Dispose pattern to allow users of the object to clean up the resources and avoid finalization". Also don't hold onto objects before making a query to the database or a webservice.

Monday, January 08, 2007

.Net Framework Clarification on Stacks and Heaps

I was reading through January issue of MSDN on the article "Identify And Prevent Memory Leaks In Managed Code", where (James Kovacs) started discussing stacks and heaps. I and a couple of other co-workers where wondering about more details on what they do and why they are needed.

Stacks: "The stack is where local variables, method parameters, return values, and other temporary values are stored during the execution of an application. A stack is allocated on a per-thread basis and serves as a scratch area for the thread to perform its work. The GC [Garbage Collector] is not responsible for cleaning up the stack because the space on the stack reserved for a method call is automatically cleaned up when a method returns. Note, however, that the GC is aware of references to objects stored on the stack. When an object is instantiated in a method, its reference (a 32-bit or 64-bit integer depending on the platform) is kept on the stack, but the object it-self is stored on the managed heap and is collected by the garbage collector once the variable has gone out of scope."

Unmanaged Heap: "The unmanaged heap is used for runtime data structures, method tables, Microsoft intermediate language (MSIL), JITed code and so forth. Unmanaged code will allocate objects on the unmanaged heap or stack depending on how the object is instantiated. Managed code can allocate unmanaged heap memory directly by calling into unmanaged Win32 APIs or by instantiating COM objects. The CLR itself uses the unmanaged heap extensively for its data structures and code."

Managed Heap: "The managed heap is where managed objects are allocated and it is the domain of the garbage collector. The CLR uses a generational, compacting GC. The GC is generational in that it ages objects as they survive garbage collections; this is a performance enhancement. All versions of the .NET Framework have used three generations, Gen0, Gen1, and Gen2 (from youngest to oldest). The GC is compacting in that it relocates objects on the managed heap to eliminate holes and keep free ememory contiguous. Moving large objects is expensive and therefore the GC allocates them on a separate Large Object Heap, which does not compact."

Tuesday, December 12, 2006

BizTalk Query: Find what schemas are deployed.

use biztalkmgmtdb
select msgtype, body_xpath, clr_namespace, clr_typename, clr_assemblyname, schema_root_name,
docspec_name
from bt_DocumentSpec
order by msgtype --(which is the schema-name)
--order by date_modified desc -- (probably the date deployed?)

BizTalk Assessment Question: Recoverable Interchange

You are a Microsoft(R) BizTalk(R) Server 2006 technology specialist for your company. You need to enable and configure the new recoverable interchange feature in BizTalk Server 2006.
Where can you enable and configure this feature? (Each correct answer presents a complete solution. Choose two.)

  • In Microsoft Visual Studio(R) 2005 while you are defining an orchestration
  • In the Tracking Profile Editor
  • In the BizTalk Server Administration Console
  • In the Business Activity Monitoring (BAM) portal
  • In Microsoft Visual Studio(R) 2005 while you are defining a custom pipeline

There are two ways of setting up the recoverable interchange in BizTalk 2006 either through the pipeline's XMLDisassembler component or through the Admin Console

BizTalk Assessment Question: MQSeries adapter

You are a Microsoft(R) BizTalk(R) Server 2006 application developer. You want to retrieve XML messages from an MQSeries queue. You want to do this in the easiest way possible.
What should you do?
  • Download and install a community-supported MQSeries adapter.
  • Use the built-in MQSeries adapter.
  • Use the MQSeries application programming interface (API) to write your own MQSeries adapter.
  • Download and install the Microsoft-supported MQSeries adapter.

Well this one is kinda obvious, Use the built-in MQSeries adapter.

"For BizTalk Server 2004 the MQSeries adapter was available as a Web
download. In BizTalk Server 2006, the MQSeries support comes built-in. With the
MQSeries adapter, organizations can use XML-enabled MQSeries investments, making it possible to more securely and reliably integrate disparate applications."

BizTalk Assessment Question: Zoom feature

Which Microsoft(R) BizTalk(R) Server 2006 designer has a new zoom feature?

  • Mapper tool
  • Schema Designer
  • Pipeline Designer
  • Orchestration Designer

"Orchestration zooming. In BizTalk 2004, working with
complex orchestrations in the Orchestration Designer sometimes requires a lot of
scrolling on the design surface to view different parts of the orchestration. In
BizTalk Server 2006, the designer has been enhanced to provide the ability to
zoom in and out on an orchestration, allowing a developer to view only those
parts of an orchestration of current interest. "

Monday, December 11, 2006

BizTalk Assessment Question: Make a schema from a postionial flat file

You are a Microsoft(R) BizTalk(R) Server 2006 application developer. You want to create a schema that is based on a positional document.

What should you do?

  • Purchase a third-party tool that converts positional documents to XML documents.
  • Count and record the starting position of each field.
  • Count and record the length of each field.
  • Count and record the ending position of each field.
  • Run the Flat File Wizard.
I think this one is kinda obvious, of course Microsoft is going to boast about the Flat File Wizard.

There are basically 3 types of flat files:
  • Delimited flat file.
  • Positional flat file.
  • A flat file with combination of Delimited and Positional records.

BizTalk Assessment Question: Allow business users to view BAM alerts and aggregations.

You are a Microsoft(R) BizTalk(R) Server 2006 technology specialist for your company. You want to allow business users to view Business Activity Monitoring (BAM) alerts and
aggregations.

What new feature of BizTalk Server 2006 should you use?
  • BAM Web service
  • Tracking Profile Editor
  • BizTalk Server Administration Console
  • BAM portal

The best answer here would be the BAM portal, where business users can set up queries and alerts on a single interface.

BizTalk Assessment Question: Send notification to business users.

You are a Microsoft(R) BizTalk(R) Server 2006 technology specialist for your company. You need to provide notification in real time to business users about changes to their
business processes.

What feature of BizTalk Server 2006 meets this need?

  • Business Activity Monitoring (BAM) activity
  • Business Activity Monitoring (BAM) alerts
  • Business rules
  • Orchestrations

In my opinion, BAM alerts would be the best answer here, since you can set it up to send notification when a certain parameter has been reached. BAM activity are just like queries which can be used in the alerts. Business rules and orchestration are more internal but still possible to send out notifications with the use of both of these, but not necessary if you have BAM setup.

BizTalk Assessment Question: What are the two BAM web services?

What two categories can you find in Business Activity Monitoring (BAM) Web services in Microsoft(R) BizTalk(R) Server 2006? (Each correct answer presents part of the
solution. Choose two.)

  1. Human Workflow Services (HWS) service
  2. BAM portal BizTalk artifacts
  3. BAM query service
  4. BAM management service

Answer: BAM query service and BAM management service

1. BAM Query Service – The service is used
by the BAM Portal to retrieve BAM instance data. The service supports the
infrastructure and is not intended to be used directly from your code. The
service is not supported and is not documented. To retrieve instance, use the
supported techniques described at http://msdn.microsoft.com/library/en-us/BTS06BizProcessMgmnt/html/ae4a8854-d5c2-4b36-a0ef-3f74e138306e.asp?frame=true.
2. BamManagementService – The following service provides, consumers the ability to manage subscriptions and alerts among other management operations