Vaccano
Vaccano

Reputation: 82427

When is memory from a WCF Call Allocated?

I have a call to a SOAP WCF Service that returns a lot of data. More than the calling Windows Mobile Device can handle.

Yet I am noticing something odd. When I make the call it looks like this:

MyContract[] myContractArray = MyService.CallToGetLotsOfDataObjects();

That does not fail. But when it iterate through myContractArray and put them into client side classes, then it fails.

At first I just said, "well, it can't handle having two copies of the data, that is just too much". But now I am wondering if myContractArray is actually holding the data after the above call. I am wondering if it is kind of like a Linq-To-SQL call where it does not get loaded till it is needed.

So here is my question, at what point below does the data get allocated on the client?

// Create the service 
var serviceLib = new MyServiceDataServiceLib();

//                           1 -----------------+                      
//                                              |                      
//                                              V 
MyContract[] myContractArray = serviceLib.WCFCallToGetLotsOfDataObjects();  
List<MyClass> myClassList = new List<MyClass>()

// 3 -----------------+                       +------------------ 2
//                    |                       |
//                    V                       v
foreach(MyContract myContractInstance in myContractArray )
{
   MyClass myClassInstance = new MyClass();
   myClassInstance.BigImage = myContractInstance.BigImage;
   myClassInstance.MoreData = myContractInstance.MoreData;
   myClassInstance.EvenMoreData = myContractInstance.EvenMoreData;
   myClassList.Add(myClassInstance);
}

Is it at:

  1. When the call is made to the server
  2. When I begin to iterate the list (less likely in my opinion)
  3. As I need each instance

I think it 1 or 3, but I am not sure which it is. Does anyone know?

(NOTE: I am using Visual Studio 2008 and .net 3.5. My client side is a Windows Mobile application)

Upvotes: 1

Views: 119

Answers (2)

casperOne
casperOne

Reputation: 74540

The allocation for the array is handled at 1. The proxy is like any other .NET object. The array is not 'transparent' in any way nor is it sparse.

Basically, when the data comes back from the service, if it is typed as an array, the array, as well as any elements in the array are fully serialized/materialized.

Upvotes: 1

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29632

My guess is that the data is allocated at the first myContractInstance.BigImage. This would be because MyContract is a proxy, but I am not sure.

You could test this by commenting out the contents of the foreach and seeing whether you still get the exception.

Upvotes: 0

Related Questions