Can any body explain me below statement of function ?
-
i want to know the what is technical meaning of below statement
sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));
shall i need to free memory allocated to SqliteManagerBGSync() ?
// in class header static SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance() // in class defination SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance() { std::map<int,SqliteManagerBGSync*>::iterator it; int threadId = pthread_self(); DBGF_TRACE("AFCS:SqliteManagerBGSync::thread Id :%d",threadId); //sqliteManagerMap.empty() Return 0 If sqliteManagerMap is Not Empty //Return 1 If sqliteManagerMap is Empty DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty()=%d",sqliteManagerMap.empty()); if(sqliteManagerMap.empty()) { DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() IF"); if(pthread_mutex_init(&databaseLock, NULL) != 0) { DBGF_TRACE("databaseLock mutex init failed"); } else { DBGF_TRACE("databaseLock mutex init Success"); } } // else // { // DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() Else"); // sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync())); // it = sqliteManagerMap.find(threadId); // DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 1"); // return it->second; // } it = sqliteManagerMap.find(threadId); if(it == sqliteManagerMap.end()) { DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::threadId Find Success"); sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync())); DBGF_TRACE("AFCS:sqliteManagerMap insert called"); it = sqliteManagerMap.find(threadId); } DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 2"); DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_current() = %d",_heap_current()); return it->second; } -
i want to know the what is technical meaning of below statement
sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));
shall i need to free memory allocated to SqliteManagerBGSync() ?
// in class header static SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance() // in class defination SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance() { std::map<int,SqliteManagerBGSync*>::iterator it; int threadId = pthread_self(); DBGF_TRACE("AFCS:SqliteManagerBGSync::thread Id :%d",threadId); //sqliteManagerMap.empty() Return 0 If sqliteManagerMap is Not Empty //Return 1 If sqliteManagerMap is Empty DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty()=%d",sqliteManagerMap.empty()); if(sqliteManagerMap.empty()) { DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() IF"); if(pthread_mutex_init(&databaseLock, NULL) != 0) { DBGF_TRACE("databaseLock mutex init failed"); } else { DBGF_TRACE("databaseLock mutex init Success"); } } // else // { // DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() Else"); // sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync())); // it = sqliteManagerMap.find(threadId); // DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 1"); // return it->second; // } it = sqliteManagerMap.find(threadId); if(it == sqliteManagerMap.end()) { DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::threadId Find Success"); sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync())); DBGF_TRACE("AFCS:sqliteManagerMap insert called"); it = sqliteManagerMap.find(threadId); } DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 2"); DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_current() = %d",_heap_current()); return it->second; }This post is deleted! -
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
Well, here you create std::pair<int,SqliteManagerBGSync*> containing threadId and pointer to SqliteManagerBGSync instance. Then that pair is passed to sqliteManagerMap.insert(...).
Yes, you have to delete SqliteManagerBGSync at some point when it is not needed anymore. -
i want to know the what is technical meaning of below statement
sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));
shall i need to free memory allocated to SqliteManagerBGSync() ?
// in class header static SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance() // in class defination SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance() { std::map<int,SqliteManagerBGSync*>::iterator it; int threadId = pthread_self(); DBGF_TRACE("AFCS:SqliteManagerBGSync::thread Id :%d",threadId); //sqliteManagerMap.empty() Return 0 If sqliteManagerMap is Not Empty //Return 1 If sqliteManagerMap is Empty DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty()=%d",sqliteManagerMap.empty()); if(sqliteManagerMap.empty()) { DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() IF"); if(pthread_mutex_init(&databaseLock, NULL) != 0) { DBGF_TRACE("databaseLock mutex init failed"); } else { DBGF_TRACE("databaseLock mutex init Success"); } } // else // { // DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() Else"); // sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync())); // it = sqliteManagerMap.find(threadId); // DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 1"); // return it->second; // } it = sqliteManagerMap.find(threadId); if(it == sqliteManagerMap.end()) { DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::threadId Find Success"); sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync())); DBGF_TRACE("AFCS:sqliteManagerMap insert called"); it = sqliteManagerMap.find(threadId); } DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 2"); DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_current() = %d",_heap_current()); return it->second; }@Qt-embedded-developer said in Can any body explain me below statement of function ?:
i want to know the what is technical meaning of below statement
sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));
shall i need to free memory allocated to SqliteManagerBGSync() ?I think the idea between this is to get access to DB connection which has been created for the current thread (as QSqlDatabase has to be used in the thread in which it has been created).
But to answer to your question, yes you have to free used memory.
The easiest way to do it, would be to use smart pointer, likeQSharedPointer==> useQSharedPointer<SqliteManagerBGSync>instead ofSqliteManagerBGSync*. -
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
Well, here you create std::pair<int,SqliteManagerBGSync*> containing threadId and pointer to SqliteManagerBGSync instance. Then that pair is passed to sqliteManagerMap.insert(...).
Yes, you have to delete SqliteManagerBGSync at some point when it is not needed anymore.@jsulm @KroMignon Can anybody explain me how to free this map and memory allocated to instance ?
-
@jsulm @KroMignon Can anybody explain me how to free this map and memory allocated to instance ?
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
Can you let me know how to free this map and memory allocated to instance ?
As written before, there are 2 options:
- use smart pointer, memory will be release when item is removed from map
- call "manually"
deleteto free memory when item is removed from map.
-
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
Can you let me know how to free this map and memory allocated to instance ?
As written before, there are 2 options:
- use smart pointer, memory will be release when item is removed from map
- call "manually"
deleteto free memory when item is removed from map.
@KroMignon can you give example for my map. how to delete & deallocate memory to it ?
-
@KroMignon can you give example for my map. how to delete & deallocate memory to it ?
@Qt-embedded-developer What map? sqliteManagerMap? If so than there is no need to delete it as it is not allocated on the heap, apparently. To delete SqliteManagerBGSync instance use "delete" keyword as usual in C++ or use shared pointer as @KroMignon already suggested two times...
-
@Qt-embedded-developer What map? sqliteManagerMap? If so than there is no need to delete it as it is not allocated on the heap, apparently. To delete SqliteManagerBGSync instance use "delete" keyword as usual in C++ or use shared pointer as @KroMignon already suggested two times...
@jsulm @KroMignon Hi i have access this instance based function in other class like below
app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase();
And actually it is complex such that i am unable to understand how to delete it ?
So i nee example to delete it.
i have attached the code for openDatabase()
int SqliteManagerBGSync::openDatabase() { DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex locking"); if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0) { DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 1"); pthread_mutex_lock(&databaseLock); } DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Locked"); if(handle != NULL){ DBGF_TRACE("AFCS:SqliteManagerBGSync::Handle success"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); return SUCCESS; } int res = sqlite3_open(DB_PATH, &handle); DBGF_TRACE("AFCS:SqliteManagerBGSync::sqlite3 open = %d",res); DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::mutex lock called"); if(res != SQLITE_OK) { DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocking"); if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0) { DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 2"); pthread_mutex_unlock(&databaseLock); } DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocked"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); ERROR_RETURN(-1); }else{ DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::Sqlite ok"); if(sqlite3_exec(handle, "PRAGMA journal_mode = WAL;PRAGMA cache_size = 100000;", NULL, 0, NULL) == SQLITE_OK) { DBGF_TRACE(" SQLITE QUERY SUCCESS: PRAGMA journal_mode = WAL;PRAGMA cache_size = 100000;"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); return SUCCESS; } else { DBGF_TRACE(" SQLITE QUERY FAIL : PRAGMA journal_mode = WAL;PRAGMA cache_size = 100000;"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); ERROR_RETURN(0); } DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); return SUCCESS; } }
below i shown other class's function where i used above function :
int CheckTotalErrorStep::FeatchTotalErrorCount() { std::string strCurrentDate="0"; strCurrentDate = boomer::utils::datetime::getCurrentDateTime("YYYY-MM-DD"); DBGF_TRACE("AFCS:ReprintTicketStep::CheckNoOfTimesTryingToRePrintTicket()"); char *errMsg; int result=0; std::string usr_query=""; intTotalInsertedErrorLogCount = 0; if(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase() != SUCCESS) { ERROR_RETURN(0); } else { std::stringstream sql; usr_query = "SELECT COUNT(INTERRORLOGID) FROM TBLERRORLOGS WHERE date(DTEERRORDATETIME) = '" + strCurrentDate + "';"; DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() : :usr_query=%s",usr_query); result = sqlite3_exec(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle, usr_query.c_str(), &GetTotalErrorCount, 0, &errMsg); DBGF_TRACE("AFCS:CheckTotalErrorStep::FeatchTotalErrorCount():result=%d",result); if(result == SQLITE_OK) { app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase(); return SQLITE_OK; } else { DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() :Error=%s",sqlite3_errmsg(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle)); app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase(); return SQLITE_ERROR; } } return result; }I am not using the QT. i am only using c++. i want to know shall i need to use shared pointer in map ?
can anybody give example to deallocate memory for above singleton based class ?
-
@jsulm @KroMignon Hi i have access this instance based function in other class like below
app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase();
And actually it is complex such that i am unable to understand how to delete it ?
So i nee example to delete it.
i have attached the code for openDatabase()
int SqliteManagerBGSync::openDatabase() { DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex locking"); if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0) { DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 1"); pthread_mutex_lock(&databaseLock); } DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Locked"); if(handle != NULL){ DBGF_TRACE("AFCS:SqliteManagerBGSync::Handle success"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); return SUCCESS; } int res = sqlite3_open(DB_PATH, &handle); DBGF_TRACE("AFCS:SqliteManagerBGSync::sqlite3 open = %d",res); DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::mutex lock called"); if(res != SQLITE_OK) { DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocking"); if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0) { DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 2"); pthread_mutex_unlock(&databaseLock); } DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocked"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); ERROR_RETURN(-1); }else{ DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::Sqlite ok"); if(sqlite3_exec(handle, "PRAGMA journal_mode = WAL;PRAGMA cache_size = 100000;", NULL, 0, NULL) == SQLITE_OK) { DBGF_TRACE(" SQLITE QUERY SUCCESS: PRAGMA journal_mode = WAL;PRAGMA cache_size = 100000;"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); return SUCCESS; } else { DBGF_TRACE(" SQLITE QUERY FAIL : PRAGMA journal_mode = WAL;PRAGMA cache_size = 100000;"); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); ERROR_RETURN(0); } DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max()); DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current()); return SUCCESS; } }
below i shown other class's function where i used above function :
int CheckTotalErrorStep::FeatchTotalErrorCount() { std::string strCurrentDate="0"; strCurrentDate = boomer::utils::datetime::getCurrentDateTime("YYYY-MM-DD"); DBGF_TRACE("AFCS:ReprintTicketStep::CheckNoOfTimesTryingToRePrintTicket()"); char *errMsg; int result=0; std::string usr_query=""; intTotalInsertedErrorLogCount = 0; if(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase() != SUCCESS) { ERROR_RETURN(0); } else { std::stringstream sql; usr_query = "SELECT COUNT(INTERRORLOGID) FROM TBLERRORLOGS WHERE date(DTEERRORDATETIME) = '" + strCurrentDate + "';"; DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() : :usr_query=%s",usr_query); result = sqlite3_exec(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle, usr_query.c_str(), &GetTotalErrorCount, 0, &errMsg); DBGF_TRACE("AFCS:CheckTotalErrorStep::FeatchTotalErrorCount():result=%d",result); if(result == SQLITE_OK) { app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase(); return SQLITE_OK; } else { DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() :Error=%s",sqlite3_errmsg(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle)); app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase(); return SQLITE_ERROR; } } return result; }I am not using the QT. i am only using c++. i want to know shall i need to use shared pointer in map ?
can anybody give example to deallocate memory for above singleton based class ?
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
And actually it is complex such that i am unable to understand how to delete it ?
So i nee example to delete it.I don't understand what looks complicated to you.
You have to delete the instance when you remove it from map. -
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
And actually it is complex such that i am unable to understand how to delete it ?
So i nee example to delete it.I don't understand what looks complicated to you.
You have to delete the instance when you remove it from map.@KroMignon actually i have seen that already completely developed project never removed it. and never deleted it.
as you can see that how i accessed GetAFCSTicketInstance() in other class.
so where i need to put "delete SqliteManagerBGSync" ?
-
@KroMignon actually i have seen that already completely developed project never removed it. and never deleted it.
as you can see that how i accessed GetAFCSTicketInstance() in other class.
so where i need to put "delete SqliteManagerBGSync" ?
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
so where i need to put "delete SqliteManagerBGSync" ?
You could do it in the destructor of the class holding sqliteManagerMap member.
-
@KroMignon actually i have seen that already completely developed project never removed it. and never deleted it.
as you can see that how i accessed GetAFCSTicketInstance() in other class.
so where i need to put "delete SqliteManagerBGSync" ?
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
actually i have seen that already completely developed project never removed it. and never deleted it.
as you can see that how i accessed GetAFCSTicketInstance() in other class.
so where i need to put "delete SqliteManagerBGSync" ?As far as I can see,
app::dbmanager::SqliteManagerBGSync::GetDBInstance()seems to be a static method, so I guess the map is also an static member of classapp::dbmanager::SqliteManagerBGSync.
To be totally clean, I would add a static methodcleanup()to this class to clear properly the map:for (const auto& kv : sqliteManagerMap) { delete kv.second; } sqliteManagerMap.clear(); -
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
so where i need to put "delete SqliteManagerBGSync" ?
You could do it in the destructor of the class holding sqliteManagerMap member.
This post is deleted! -
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
actually i have seen that already completely developed project never removed it. and never deleted it.
as you can see that how i accessed GetAFCSTicketInstance() in other class.
so where i need to put "delete SqliteManagerBGSync" ?As far as I can see,
app::dbmanager::SqliteManagerBGSync::GetDBInstance()seems to be a static method, so I guess the map is also an static member of classapp::dbmanager::SqliteManagerBGSync.
To be totally clean, I would add a static methodcleanup()to this class to clear properly the map:for (const auto& kv : sqliteManagerMap) { delete kv.second; } sqliteManagerMap.clear();@KroMignon as you can see from my function that i have taken the local map in function.so on scope get completed this map also get deleted. But there is i think SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
delete SqliteManagerBGSync() ; in cleanup() memthod.
May be i am wrong. if it is then please correct me .
-
@KroMignon as you can see from my function that i have taken the local map in function.so on scope get completed this map also get deleted. But there is i think SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
delete SqliteManagerBGSync() ; in cleanup() memthod.
May be i am wrong. if it is then please correct me .
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
delete SqliteManagerBGSync() ;
Does not make sense and is not valid C++ - you are trying to delete a new stack allocated SqliteManagerBGSync instance...
-
@KroMignon as you can see from my function that i have taken the local map in function.so on scope get completed this map also get deleted. But there is i think SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
delete SqliteManagerBGSync() ; in cleanup() memthod.
May be i am wrong. if it is then please correct me .
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
delete SqliteManagerBGSync() ; in cleanup() memthod.
May be i am wrong. if it is then please correct me .I don't want to hurt, just to know how to help you, but what are your programming skills?
Do you know what are static methods or classes?
According to you code extract,SqliteManagerBGSyncis a class.
I guess methodGetDBInstance()is declared in header as follow:class SqliteManagerBGSync { public: static SqliteManagerBGSync* GetDBInstance(); };Correct or wrong?
-
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
delete SqliteManagerBGSync() ;
Does not make sense and is not valid C++ - you are trying to delete a new stack allocated SqliteManagerBGSync instance...
@jsulm So then just let me know this local map allocated the dynamic memory to class when and how to delete it with example. still i am misinterpret it then let me know.
-
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
delete SqliteManagerBGSync() ; in cleanup() memthod.
May be i am wrong. if it is then please correct me .I don't want to hurt, just to know how to help you, but what are your programming skills?
Do you know what are static methods or classes?
According to you code extract,SqliteManagerBGSyncis a class.
I guess methodGetDBInstance()is declared in header as follow:class SqliteManagerBGSync { public: static SqliteManagerBGSync* GetDBInstance(); };Correct or wrong?
@KroMignon yes it is static. thanks. just let me help me how to make this code proper.
Because i have see that my application is get restarted due too much heap utilization.
and i think this above code is reason for that.
-
@KroMignon yes it is static. thanks. just let me help me how to make this code proper.
Because i have see that my application is get restarted due too much heap utilization.
and i think this above code is reason for that.
@Qt-embedded-developer said in Can any body explain me below statement of function ?:
yes it is static. thanks. just let me help me how to make this code proper.
Because i have see that my application is get restarted due too much heap utilization.
and i think this above code is reason for that.This code don't look bad to me and I don't think it is the place where heap memory is consuming.
As written before, it will only ensure that you are using the rightSqliteManagerBGSyncfor the current thread and create a newSqliteManagerBGSyncif there is no one already created for current thread.