Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c++ - STL container leak -


i'm using vector container hold instances of object contain 3 ints , 2 std::strings, created on stack , populated function in class running app through deleaker shows std::strings object leaked. here's code:

// populator function: void populatorclass::populate(std::vector<myclass>& list) {     // m_mainlist contains list of pointers master objects     for( std::vector<myclass*>::iterator = m_mainlist.begin(); != m_mainlist.end(); it++ ) {         list.push_back(**it);     } }  // class definition class myclass { private:     std::string m_name;     std::string m_description;     int m_ntype;     int m_ncategory;     int m_nsubcategory; };  // code causing problem: std::vector<myclass> list; populatorclass.populate(list); 

when run through deleaker leaked memory in allocator std::string classes.

i'm using visual studio 2010 (crt).

is there special need make strings delete when unwinding stack , deleting vector?

thanks, j

every time got problem stl implementation doing strange or wrong memory leak, try this :

  • reproduce basic example of try achieve. if runs without leak, problem in way fill data. it's probable source of problem (i mean own code).

not tested simple on-the-fly example specific problem :

#include <string> #include <sstream>   // class definition struct myclass  { // struct convenience     std::string m_name;     std::string m_description;     int m_ntype;     int m_ncategory;     int m_nsubcategory; };   // prototype of populator function: void populate(std::vector<myclass>& list) {     const int max_type_idx = 4;     const int max_category_idx = 8;     const int max_sub_category_idx = 6;      for( int type_idx = 0; type_idx < max_type_idx ; ++type_idx)         for( int category_idx = 0; category_idx < max_category_idx ; ++category_idx)              for( int sub_category_idx = 0; sub_category_idx < max_sub_category_idx ; ++sub_category_idx)              {                    std::stringstream name_stream;                    name_stream << "object_" << type_idx << "_" << category_idx << "_" << sub_category_idx ;                    std::stringstream desc_stream;                    desc_stream << "this object of type n°" << type_idx << ".\n";                    desc_stream << "it of category n°" << category_idx << ",\n";                    desc_stream << "and of sub-category n°" << category_idx << "!\n";                     myclass object;                    object.m_name = name_stream.str();                    object.m_description = desc_stream.str();                    object.m_ntype = type_idx;                    m_ncategory =                     m_nsubcategory =                     list.push_back( object );              } }   int main() {     // code causing problem:     std::vector<myclass> list;     populate(list);      // memory leak check?     return 0;  } 
  • if still got memory leak, first check it's not false-positive leak detection software.
  • then if it's not, google memory leak problems stl implementation (most of time on compiler developer website). implementor might provide bug tracking tool search in same problem , potential solution.
  • if still can't find source of leak, maybe try build project different compiler (if can) , see if have same effect. again if leak still occurs, problem have lot of chances come code.

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -