Comments (7)
Relm4:
use gtk::prelude::*;
use item::Item;
use relm4::{
factory::{FactoryComponent, FactoryVecDeque, FactoryView},
gtk,
prelude::*,
FactorySender,
};
use std::time::Duration;
fn main() {
gtk::init().unwrap();
let app = relm4::main_application();
RelmApp::from_app(app).run::<List>(());
}
pub struct List {
items: FactoryVecDeque<Item>,
}
#[derive(Debug)]
pub enum ListInput {
Update,
}
impl SimpleComponent for List {
type Init = ();
type Input = ListInput;
type Output = ();
type Root = gtk::ApplicationWindow;
type Widgets = ();
fn init_root() -> Self::Root {
gtk::ApplicationWindow::builder().build()
}
fn init(
_init: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let list = gtk::Box::builder().build();
root.set_child(Some(&{
let container = gtk::ScrolledWindow::builder().build();
container.set_child(Some(&list));
container
}));
let items = FactoryVecDeque::builder().launch(list).detach();
let model = Self { items };
std::thread::spawn({
let sender = sender.clone();
move || loop {
sender.input(ListInput::Update);
std::thread::sleep(Duration::from_secs(1));
}
});
ComponentParts { widgets: (), model }
}
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
match message {
ListInput::Update => {
let mut guard = self.items.guard();
guard.clear();
for _ in 0..10000 {
guard.push_back(Item {});
}
}
}
}
}
mod item {
use super::*;
#[derive(Clone)]
pub struct Item;
type RootWidget = gtk::Box;
#[derive(Debug)]
pub struct FactoryWidgets {}
impl FactoryComponent for Item {
type Init = Self;
type Input = ();
type Output = ();
type CommandOutput = ();
type ParentWidget = gtk::Box;
type Root = RootWidget;
type Widgets = FactoryWidgets;
type Index = DynamicIndex;
fn init_root(&self) -> Self::Root {
RootWidget::builder()
.hexpand(false)
.vexpand(true)
.halign(gtk::Align::Start)
.build()
}
fn init_widgets(
&mut self,
_index: &DynamicIndex,
_root_widget: Self::Root,
_returned_widget: &<Self::ParentWidget as FactoryView>::ReturnedWidget,
_sender: FactorySender<Self>,
) -> Self::Widgets {
Self::Widgets {}
}
fn init_model(value: Self::Init, _index: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
value
}
}
}
GTK4:
use gtk::{prelude::*, Application, ApplicationWindow};
use relm4::{prelude::gtk, RelmRemoveAllExt};
use std::time::Duration;
fn main() {
let application = Application::builder()
.application_id("com.example.list")
.build();
application.connect_activate(|app| {
let window = ApplicationWindow::builder()
.application(app)
.default_width(400)
.default_height(400)
.build();
window.set_child(Some(&{
let container = gtk::ScrolledWindow::builder().build();
container.set_child(Some(&{
let list = gtk::Box::builder().build();
gtk::glib::timeout_add_local(Duration::from_secs(1), {
let list = gtk::glib::clone::Downgrade::downgrade(&list);
move || {
let Some(list) = list.upgrade()
else {
return false.into();
};
list.remove_all();
for _ in 0..10000 {
list.append(&{ gtk::Box::builder().build() });
}
true.into()
}
});
list
}));
container
}));
window.show();
});
application.run();
}
from relm4.
Thanks for the report. This is actually not quite unexpected because FactoryVecDeque
is using a little bit of unsafe
to make it possible to implement the Index
trait. Maybe something in the logic is wrong so that the destructor isn't run which would free the allocation.
Since we just published version 0.7 and 0.8, would you mind checking whether the problem exists there as well?
from relm4.
@AaronErhardt
Thanks for the quick reply. This is the result of running on Relm 0.8.
I first found this issue with Relm 0.6 and was going to report the issue, but I just learned that Relm 0.7/0.8 has just been released (Congratulations!🎉)
So I upgraded my crate in hopes that this issue had been resolved, but alas, it was not.
from relm4.
The leak seems to be caused by gtk-rs-core and is simply triggered very often by Relm4s factories. Let's see what the gtk-rs devs say about this (you can follow the referenced issue).
from relm4.
Thank you!
from relm4.
The memory leak should be fixed in gtk-rs in their latest versions. Can you confirm whether it works now?
from relm4.
Oh, I have confirmed that it has been fixed. Thanks a lot!
from relm4.
Related Issues (20)
- All versions after 0.6.2 include libadwaita by default HOT 5
- Allow customizing stack properties
- i want to override window exit event but how can i do HOT 1
- GLib-GObject-CRITICAL on shutdown of app with root SimpleAsyncComponent and AsyncController with adw::PreferencesWindow HOT 1
- Fuzzy font on Windows HOT 4
- Support for `adw::PreferencesPage` HOT 1
- Example `components.rs` is not showing its dialog
- `match` destructuring doesn't work with the `template` macro HOT 1
- Rewrite `Alert` component to avoid using `MessageDialog` HOT 3
- Create a `relm4-css` crate? HOT 2
- Add the ability to `forward` messages to multiple receivers
- Missing LICENSE Files in Rust Crates
- initialize SharedState without Default HOT 2
- Add AsyncFactoryComponent to prelude HOT 1
- FactoryComponent + TypedGridView + GridPosition HOT 1
- relm4::app::RelmApp::run_async catches cli args which causes panic
- Please enable libadwaita v1_6 feature HOT 2
- Is accessing a returned widget in Component::update_view possible? HOT 2
- Icons are not correctly displayed HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from relm4.