none
Out of memory when creating 1500 folders in 1 pst files RRS feed

  • Question

  • Hi Guys, I know 1500 folders are a lot but they do not contain any messages. I have an add-in for Outlook 2010 and on startup I create a PST and add it to Outlook. Then I start creating folders, at the mark of 1500 approximatel i get the out of memory error. These folders do not contain any messages. I tried the 2 solutions suggested using the UseLegacyCacheSize and increase the SharedMemory however it did not fix my problems. Do you have any workaround for this problem?
    Thursday, March 21, 2013 7:26 AM

Answers

  • write your app with better memory consumption
    • Marked as answer by 3ala2 Thursday, March 21, 2013 10:53 AM
    Thursday, March 21, 2013 10:27 AM
  • I would still try to think of an alternate way to architect this, I think you're going to have nothing but problems with the current architecture. No matter how you try to release objects and monitor your memory and resource usage you're going to have a lot of memory and other problems. For example, in Outlook 2013 if you tried to create 1500 folders on startup you'd get your code disabled as a slow starting addin unless you modifed the registry to avoid that.
     
    Instead of having users drag items to one of 1500 folders, why not just have them drag them to 1 doc management folder where they'd get prompted to select a categorization from lists or treeviews or something like that. You'd have to monitor just one folder in that case. The categorization would tell you where to place the item in the doc management system.
     
    I'd push for something like that.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "3ala2" <=?utf-8?B?M2FsYTI=?=> wrote in message news:0972b714-7ba4-4fa9-9ad3-ac8f2636ac51...
    You mentioned that you're creating 1500 folders and they are empty. That brings up the question of why do you need to create 1500 or more folders? What are all those folders being used for? What are you monitoring using the BeforeItemMove() event handlers? I'd question the basic design architecture if it requires handling 1500 or more folder events.
    Here's an example, I don't know your design so I don't know if it's appropriate for your application, but it's an alternate idea.
    Monitor when the ActiveExplorer.CurrentFolder object changes, which can be done by monitoring Explorer.BeforeFolderSwitch(). Then set up just 1 handler for BeforeItemMove() on that new folder. Remove the handler for the previous current folder.
    With that design you only have 1 handler active and instantiated at a time, you should never run into memory or resource errors with that sort of architecture.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "3ala2" <=?utf-8?B?M2FsYTI=?=> wrote in message news:260d78b4-9ff8-4b1f-9462-3e59bd7f07cd...
    ok Thanks.

    Ken Slovak MVP - Outlook

    Thanks Ken for your reply. Actuallly i think i mislead everyone with BeforeItemMove. The event I am adding is the ItemAdd event. The idea is that we have a document management system that has its hierarchy structure. And we are trying to replicate the structure in this outlook Add-in so that people can drag and drop emails and they get logged into the document management system. Once an email is dragged to a folder, I log it in and then delete the email immediately. Therefore these folders will always be empty at least for phase 1 of the product. The operation is done when an email is dropped in the folder and that is why I need this event to be registered on all those folders to know to which folder to log it.

    Appreciate your feedback. Thanks.


    Ken Slovak MVP - Outlook
    • Marked as answer by 3ala2 Friday, March 22, 2013 3:47 PM
    Friday, March 22, 2013 2:46 PM

All replies

  • Have you verified that problem actually comes from native Outlook code and not from .net side?
    Thursday, March 21, 2013 8:18 AM
  • Well i have tried to. I concluded that this is an Outlook problem because what i did is that i freed lots of memory in my code by removing some functionalities and data, and i inspected VMMAP although i don't claim I can understand everything it says. But what I noticed is that whatever my add-in is taking up in memory, adding folders always fails at the 1744 folders mark. On other machines with the same add-in sometimes it goes more. So I assumed it is a function of the PST files and the number of objects in the Folders list that has some limited amount of memory. What do yo suggest? Thanks.
    Thursday, March 21, 2013 8:28 AM
  • Maybe there is some pst or MAPI limit, someone with more knowledge should answer this. As for .net - do you store folder references somewhere? or do you release them just after creation? show us your code for Whole folder creation routine.
    Thursday, March 21, 2013 9:00 AM
  • All these folder are wrapped in a global variable list of folder wrappers since i need events to be alive all the time. I am adding on each folder a BeforeItemMove event.
    Thursday, March 21, 2013 9:14 AM
  • for sake of this investigation, please call Marshal.ReleaseComObject on that folder right after creation and do not store it anywhere nor attach any events, just create, release and go for another turn of loop.
    Thursday, March 21, 2013 9:25 AM
  • for sake of this investigation, please call Marshal.ReleaseComObject on that folder right after creation and do not store it anywhere nor attach any events, just create, release and go for another turn of loop.

    I did that. I was able to create 5900 folders without any errors or problems. What do I have to do now?
    Thursday, March 21, 2013 10:15 AM
  • write your app with better memory consumption
    • Marked as answer by 3ala2 Thursday, March 21, 2013 10:53 AM
    Thursday, March 21, 2013 10:27 AM
  • But the problem is i need the wrapper and the events on the folders. I cannot dispose those at any point. Any suggestions?
    Thursday, March 21, 2013 10:29 AM
  • maybe try going down with C++ and Extended MAPI since i think beforeitemmove is actually data level event. Or you could try to change architecture of your solution. 
    Thursday, March 21, 2013 10:38 AM
  • ok Thanks.
    Thursday, March 21, 2013 10:53 AM
  • You mentioned that you're creating 1500 folders and they are empty. That brings up the question of why do you need to create 1500 or more folders? What are all those folders being used for? What are you monitoring using the BeforeItemMove() event handlers? I'd question the basic design architecture if it requires handling 1500 or more folder events.
     
    Here's an example, I don't know your design so I don't know if it's appropriate for your application, but it's an alternate idea.
     
    Monitor when the ActiveExplorer.CurrentFolder object changes, which can be done by monitoring Explorer.BeforeFolderSwitch(). Then set up just 1 handler for BeforeItemMove() on that new folder. Remove the handler for the previous current folder.
     
    With that design you only have 1 handler active and instantiated at a time, you should never run into memory or resource errors with that sort of architecture.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "3ala2" <=?utf-8?B?M2FsYTI=?=> wrote in message news:260d78b4-9ff8-4b1f-9462-3e59bd7f07cd...
    ok Thanks.

    Ken Slovak MVP - Outlook
    Thursday, March 21, 2013 2:19 PM
  • You mentioned that you're creating 1500 folders and they are empty. That brings up the question of why do you need to create 1500 or more folders? What are all those folders being used for? What are you monitoring using the BeforeItemMove() event handlers? I'd question the basic design architecture if it requires handling 1500 or more folder events.
    Here's an example, I don't know your design so I don't know if it's appropriate for your application, but it's an alternate idea.
    Monitor when the ActiveExplorer.CurrentFolder object changes, which can be done by monitoring Explorer.BeforeFolderSwitch(). Then set up just 1 handler for BeforeItemMove() on that new folder. Remove the handler for the previous current folder.
    With that design you only have 1 handler active and instantiated at a time, you should never run into memory or resource errors with that sort of architecture.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "3ala2" <=?utf-8?B?M2FsYTI=?=> wrote in message news:260d78b4-9ff8-4b1f-9462-3e59bd7f07cd...
    ok Thanks.

    Ken Slovak MVP - Outlook

    Thanks Ken for your reply. Actuallly i think i mislead everyone with BeforeItemMove. The event I am adding is the ItemAdd event. The idea is that we have a document management system that has its hierarchy structure. And we are trying to replicate the structure in this outlook Add-in so that people can drag and drop emails and they get logged into the document management system. Once an email is dragged to a folder, I log it in and then delete the email immediately. Therefore these folders will always be empty at least for phase 1 of the product. The operation is done when an email is dropped in the folder and that is why I need this event to be registered on all those folders to know to which folder to log it.

    Appreciate your feedback. Thanks.

    Thursday, March 21, 2013 6:56 PM
  • I would still try to think of an alternate way to architect this, I think you're going to have nothing but problems with the current architecture. No matter how you try to release objects and monitor your memory and resource usage you're going to have a lot of memory and other problems. For example, in Outlook 2013 if you tried to create 1500 folders on startup you'd get your code disabled as a slow starting addin unless you modifed the registry to avoid that.
     
    Instead of having users drag items to one of 1500 folders, why not just have them drag them to 1 doc management folder where they'd get prompted to select a categorization from lists or treeviews or something like that. You'd have to monitor just one folder in that case. The categorization would tell you where to place the item in the doc management system.
     
    I'd push for something like that.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "3ala2" <=?utf-8?B?M2FsYTI=?=> wrote in message news:0972b714-7ba4-4fa9-9ad3-ac8f2636ac51...
    You mentioned that you're creating 1500 folders and they are empty. That brings up the question of why do you need to create 1500 or more folders? What are all those folders being used for? What are you monitoring using the BeforeItemMove() event handlers? I'd question the basic design architecture if it requires handling 1500 or more folder events.
    Here's an example, I don't know your design so I don't know if it's appropriate for your application, but it's an alternate idea.
    Monitor when the ActiveExplorer.CurrentFolder object changes, which can be done by monitoring Explorer.BeforeFolderSwitch(). Then set up just 1 handler for BeforeItemMove() on that new folder. Remove the handler for the previous current folder.
    With that design you only have 1 handler active and instantiated at a time, you should never run into memory or resource errors with that sort of architecture.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "3ala2" <=?utf-8?B?M2FsYTI=?=> wrote in message news:260d78b4-9ff8-4b1f-9462-3e59bd7f07cd...
    ok Thanks.

    Ken Slovak MVP - Outlook

    Thanks Ken for your reply. Actuallly i think i mislead everyone with BeforeItemMove. The event I am adding is the ItemAdd event. The idea is that we have a document management system that has its hierarchy structure. And we are trying to replicate the structure in this outlook Add-in so that people can drag and drop emails and they get logged into the document management system. Once an email is dragged to a folder, I log it in and then delete the email immediately. Therefore these folders will always be empty at least for phase 1 of the product. The operation is done when an email is dropped in the folder and that is why I need this event to be registered on all those folders to know to which folder to log it.

    Appreciate your feedback. Thanks.


    Ken Slovak MVP - Outlook
    • Marked as answer by 3ala2 Friday, March 22, 2013 3:47 PM
    Friday, March 22, 2013 2:46 PM
  • Thank you Ken. I will keep pushing for this since that was my first suggestion for this app.
    Sunday, March 24, 2013 9:01 PM