Deallocate memory to singleton class which access database ?
-
@jsulm Okay thanks. but still i am getting below errors:
"src\SqliteManagerBGSync.cpp", line 27: Error: #260-D: explicit type is missing ("int" assumed)
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #252: reference variable "kv" requires an initializer
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #29: expected an expression
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 28: Error: #153: expression must have class type
delete kv.second;@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
Okay thanks. but still i am getting below errors:
Do your compiler support C++11 and did you enable C++11 support (eg. add
CONFIG += c++11
in your PRO file)? -
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
Okay thanks. but still i am getting below errors:
Do your compiler support C++11 and did you enable C++11 support (eg. add
CONFIG += c++11
in your PRO file)?@KroMignon Hi i am not using qt . and sorry i can not enable C++ 11 because my compiler not support it. i can access map like std::map .
-
@jsulm Okay thanks. but still i am getting below errors:
"src\SqliteManagerBGSync.cpp", line 27: Error: #260-D: explicit type is missing ("int" assumed)
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #252: reference variable "kv" requires an initializer
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #29: expected an expression
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 28: Error: #153: expression must have class type
delete kv.second;SqliteManagerBGSync(); cleanup();
both are missing the return type, and also make sure to fix them in the *.cpp file as well!
-
SqliteManagerBGSync(); cleanup();
both are missing the return type, and also make sure to fix them in the *.cpp file as well!
@J-Hilk i have changed it . i have used void, But still i am getting as below mentioned error:
"src\SqliteManagerBGSync.cpp", line 27: Error: #260-D: explicit type is missing ("int" assumed)
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #252: reference variable "kv" requires an initializer
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #29: expected an expression
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 28: Error: #153: expression must have class type
delete kv.second; -
@J-Hilk i have changed it . i have used void, But still i am getting as below mentioned error:
"src\SqliteManagerBGSync.cpp", line 27: Error: #260-D: explicit type is missing ("int" assumed)
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #252: reference variable "kv" requires an initializer
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #29: expected an expression
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 27: Error: #65: expected a ";"
for (const auto& kv : sqliteManagerMap) {
^
"src\SqliteManagerBGSync.cpp", line 28: Error: #153: expression must have class type
delete kv.second;@Qt-embedded-developer As @KroMignon already asked you: do you have a C++11 capable compiler? And is C++11 activated?
-
@Qt-embedded-developer As @KroMignon already asked you: do you have a C++11 capable compiler? And is C++11 activated?
@jsulm no i have not. So what i have to change in below function:
SqliteManagerBGSync::cleanup() { for (const auto& kv : sqliteManagerMap) { delete kv.second; } sqliteManagerMap.clear(); }
-
@KroMignon Hi i am not using qt . and sorry i can not enable C++ 11 because my compiler not support it. i can access map like std::map .
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
Hi i am not using qt . and sorry i can not enable C++ 11. i can access map like std::map .
The problem is not std::map<>() but the way you iterate through the map:
for (const auto& kv : sqliteManagerMap)
requires at least C++11 support enabled! (cf. https://en.cppreference.com/w/cpp/container/map)I don't know which kind of C++ compiler you are using, for GCC for example enabling C++11 is done with
-std=c++11
or-std=gnu++11
-
@jsulm no i have not. So what i have to change in below function:
SqliteManagerBGSync::cleanup() { for (const auto& kv : sqliteManagerMap) { delete kv.second; } sqliteManagerMap.clear(); }
@Qt-embedded-developer Then you can't use auto, write the type instead of auto
-
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
Hi i am not using qt . and sorry i can not enable C++ 11. i can access map like std::map .
The problem is not std::map<>() but the way you iterate through the map:
for (const auto& kv : sqliteManagerMap)
requires at least C++11 support enabled! (cf. https://en.cppreference.com/w/cpp/container/map)I don't know which kind of C++ compiler you are using, for GCC for example enabling C++11 is done with
-std=c++11
or-std=gnu++11
@KroMignon i can not enable it like that because any change like that not allowed in my device.
-
@KroMignon i can not enable it like that because any change like that not allowed in my device.
@Qt-embedded-developer than do a normal for(x; x<y; ++x) loop
-
@Qt-embedded-developer than do a normal for(x; x<y; ++x) loop
@J-Hilk ,@jsulm ,@jsulm ,@KroMignon Thanks for enormous support.
i have written like it below and now its not show any error:
void SqliteManagerBGSync::cleanup() { for (short int i =0 ; i<sizeof(sqliteManagerMap);i++) { delete sqliteManagerMap[i]; } sqliteManagerMap.clear(); }
-
@J-Hilk ,@jsulm ,@jsulm ,@KroMignon Thanks for enormous support.
i have written like it below and now its not show any error:
void SqliteManagerBGSync::cleanup() { for (short int i =0 ; i<sizeof(sqliteManagerMap);i++) { delete sqliteManagerMap[i]; } sqliteManagerMap.clear(); }
@Qt-embedded-developer
usingsizeof
is almost certainly wrong here.std::map has a size() function, please use that.
https://en.cppreference.com/w/cpp/container/map/size -
@KroMignon i can not enable it like that because any change like that not allowed in my device.
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
i can not enable it like that because any change like that not allowed in my device.
As @jsulm already wrote before, replace
auto
with the corresponding type:for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it) { ... }
-
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
i can not enable it like that because any change like that not allowed in my device.
As @jsulm already wrote before, replace
auto
with the corresponding type:for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it) { ... }
@KroMignon
IIRC range based for loops is a c++11 feature in itself 🤔never mind, I think need a break!
-
@KroMignon
IIRC range based for loops is a c++11 feature in itself 🤔never mind, I think need a break!
@J-Hilk said in Deallocate memory to singleton class which access database ?:
IIRC range based for loops is a c++11 feature in itself 🤔
Are you sure? I don't believe that
std::map<>::iterator
support is comming with C++11. -
@J-Hilk said in Deallocate memory to singleton class which access database ?:
IIRC range based for loops is a c++11 feature in itself 🤔
Are you sure? I don't believe that
std::map<>::iterator
support is comming with C++11.@KroMignon I think @J-Hilk misunderstood your code: you are not using range based loop
-
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
i can not enable it like that because any change like that not allowed in my device.
As @jsulm already wrote before, replace
auto
with the corresponding type:for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it) { ... }
@KroMignon Here inside for loop i need to write
for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it) { delete it; }
or what i need to write to deallocate memory ?
-
@KroMignon Here inside for loop i need to write
for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it) { delete it; }
or what i need to write to deallocate memory ?
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
delete it;
delete it->second;
of course
-
@KroMignon Here inside for loop i need to write
for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it) { delete it; }
or what i need to write to deallocate memory ?
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
or what i need to write to deallocate ?
Please, take time to read std::map<> documentation.
You are using a map iterator, so it is a container object which gives you access to key and value.delete it
do not make sense!You want to delete the pointer hold in the value part:
delete it->second
-
@Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:
or what i need to write to deallocate ?
Please, take time to read std::map<> documentation.
You are using a map iterator, so it is a container object which gives you access to key and value.delete it
do not make sense!You want to delete the pointer hold in the value part:
delete it->second
This post is deleted!